Hey all,
I have troubles writing my own macro. I have been given a rough guide to try out but i think there's a problem with the logic.
f1 is a column and f2 is another column .
I want to rename them as a column named email.
If I understand your problem correct then you don't need macro coding at all. See below:
data have (drop=_:);
array F {20} 8.;
do _i=1 to 10;
do _j=1 to dim(F);
f(_j)=ceil(ranuni(0)*10);
end;
output;
end;
run;
data want(keep=email);
set have;
array vars {*} _numeric_;
do _i=1 to dim(vars);
email=vars(_i);
output;
end;
run;
Hey Patrick , Supposedly i have 10 columns (see below)
FILE A
F1 to F10 are the columns.
F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 |
There | are | 40 | students | in | the | class | . | They | are |
all | studying | for | Math | and | Science | . | They | have | learnt |
valuable | lessons | from | the | Classes. | The | teachers | are | proud | of |
them | . |
FILE B
Become to F1 as the only column with many rows.
F1 |
There |
are |
40 |
students |
in |
the |
class |
. |
They |
are |
all |
studying |
for |
Math |
and |
Science. |
They |
have |
learnt |
valuable |
lessons |
from |
the |
classes. |
The |
teachers |
are |
proud |
of |
them |
. |
The codes which you have written . Converted the dataset of File A to numerics and then File B to just 1 column with many rows. Yes, this is the expected outcome but i am looking for the words and not numeric . Could you help in the codes you have written. FYI, my real dataset has 92 columns with hundreds of rows.
Thank you .
Assuming all your variables are character a simple change to the code will do. Make sure to define a length for email which is as long as the longest of your input character variables.
data have (drop=_:);
array F {20} $20.;
do _i=1 to 10;
do _j=1 to dim(F);
f(_j)=cats('ABC',ceil(ranuni(0)*10));
end;
output;
end;
run;
data want(keep=email);
set have;
array vars {*} _character_;
length email $ 20;
do _i=1 to dim(vars);
email=vars(_i);
output;
end;
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.