BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
alepage
Barite | Level 11

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;

 

 

 

 

 

 

 

View solution in original post

2 REPLIES 2
Astounding
PROC Star

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.;

alepage
Barite | Level 11

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 836 views
  • 0 likes
  • 2 in conversation