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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.