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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.