Hello,
I have test my code and it seems to work.
However when I disconnect from server and start over, the program has difficulties to evaluate macro variables.
(see log file)
Does someone could help me with that issue?
Can we carry out this task without using macro variable because the number of column could be as high as 1000 and the macro variable used ram memory;
data test;
array var{5} $;
run;
/*Would like to set random column length*/
%macro test;
%do i=1 %to 5;
data test;
call symput('name',cat("var",&i));
call symputx('val',max(round(ranuni(0)*50,1),10));
length &Name. $ &val.;
format &Name. $&val..;
set test;
%end;
run;
%mend test;
%test;
Thanks in advance for your help.
alepage
Here's my corrected code...it works.
%let MaxNbChar =50;
%let NbVar=450;
data test;
array var{&NbVar.} $ ;
run;
/*Would like to set random column length*/
%macro test;
%do i=1 %to &NbVar.;
%let name=var&i;
%let val=%sysfunc(max(%sysfunc(round(%sysfunc(ranuni(-1))*&MaxNbChar.,1)),10));
data test;
length &Name. $ &val.;
format &Name. $&val..;
set test;
%end;
Data test;
retain var1-var&NbVar;
set test;
run;
%mend test;
%test;
Macro variables created with CALL SYMPUT are not available for use in the same DATA step that creates them. Presumably you got your program to work by running the program twice (first time failing, but creating &NAME, second time working).
To get around that, get rid of the first CALL SYMPUT. Instead, before the DATA step use:
%let name = var&i.;
Here's my corrected code...it works.
%let MaxNbChar =50;
%let NbVar=450;
data test;
array var{&NbVar.} $ ;
run;
/*Would like to set random column length*/
%macro test;
%do i=1 %to &NbVar.;
%let name=var&i;
%let val=%sysfunc(max(%sysfunc(round(%sysfunc(ranuni(-1))*&MaxNbChar.,1)),10));
data test;
length &Name. $ &val.;
format &Name. $&val..;
set test;
%end;
Data test;
retain var1-var&NbVar;
set test;
run;
%mend test;
%test;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.