BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

Hi,

I was trying to understand the following code:

If max=3

then with the first call symput in the below code we get n=3

in the do loop does it have to be do i=1 to 3 ?or

do i=1 to max????

Also in the call symputx step will it be list=t_1 d_1 in the first loop and EACH TIME WIL THE LIST BE OVER RIDDEN??

data _null_;

set x2;

call symputx('n',max);

length x $ 32767;

do i=1 to max;

  x=catt(x,' t_',left(i),' d_',left(i));

end;

  call symputx('list',x);
 
run;

Thanks

4 REPLIES 4
Reeza
Super User

Why not run it for a small subset to figure out what it's doing?

Add in some put statements (see below) if you're having difficulties

data _null_;

set x2;

call symputx('n',max);

put "Max:" max;

length x $ 32767;

do i=1 to max;

  x=catt(x,' t_',left(i),' d_',left(i));

put "X: " x;

end;

  call symputx('list',x);

run;

robertrao
Quartz | Level 8

Even when i use

put "N:" max;

i get n=3

robertrao
Quartz | Level 8

So Basiclly X is over ridden and what remians in X at the last iteration is retained in the LIST macro variable

Is that right?

Thnx

ballardw
Super User

The values of the macro variables will always be the those assigned for the last record in the input dataset the way you are creating them. If you want to create a macro variable for each record in the dataset you'll need to create a name for each pass.

For example:

length nname listname $ 20;

nname = cats('n',_n_);

listname = cats('list',_n_);

call symputx (nname,max);

call symputx (listname,x);

This will create macro variables n1, n2, n3 .... and list1, list2, list3 ...

You will probably want to have a macro variable with the count

Call symputx ('counter', put(_n_,f10.0));

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 707 views
  • 6 likes
  • 3 in conversation