data l;
input id$;
cards;
d
run;
%let a=5;
%macro tt;
data l2;
set l;
%do i= 1 %to &a;
t=id||"&i.";
t=compress(t,'');
run;
%end;
%mend;
%tt;
proc print data=l2;
run;
Tryed in this way but no working
I want to create the observations bases on macro variable a
output
id1
id2
id3
id4
id5
You have a couple of errors in your code.
You can also use the CATS function to concatenate the data and remove unwanted blanks, which will save using COMPRESS separately. There's some slight confusion as to what you want to show in your output, should it be id1, id2 etc or d1, d2 etc ? To achieve the former, put quotes around id in the concatenate function, otherwise leave it as is and it will take the value of the column id. Here is the code I think you want, I've added a length statement to prevent the default $200. You don't really need the macro either, just use a normal loop within the datastep.
%let a=5;
data l2;
length id $6;
set l;
do i= 1 to &a;
t=cats(id,i);
output;
end;
run;
proc print data=l2;
run;
Message was edited by: Keith Timms Obviously the length statement should against column t, not id.
You have a couple of errors in your code.
You can also use the CATS function to concatenate the data and remove unwanted blanks, which will save using COMPRESS separately. There's some slight confusion as to what you want to show in your output, should it be id1, id2 etc or d1, d2 etc ? To achieve the former, put quotes around id in the concatenate function, otherwise leave it as is and it will take the value of the column id. Here is the code I think you want, I've added a length statement to prevent the default $200. You don't really need the macro either, just use a normal loop within the datastep.
%let a=5;
data l2;
length id $6;
set l;
do i= 1 to &a;
t=cats(id,i);
output;
end;
run;
proc print data=l2;
run;
Message was edited by: Keith Timms Obviously the length statement should against column t, not id.
Thqs
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.