Help using Base SAS procedures

CODE HELP

Reply
Super Contributor
Posts: 1,040

CODE HELP

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

Super User
Posts: 17,907

Re: CODE HELP

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;

Super Contributor
Posts: 1,040

Re: CODE HELP

Even when i use

put "N:" max;

i get n=3

Super Contributor
Posts: 1,040

Re: CODE HELP

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

Super User
Posts: 10,538

Re: CODE HELP

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

Ask a Question
Discussion stats
  • 4 replies
  • 213 views
  • 6 likes
  • 3 in conversation