Help using Base SAS procedures

call symput

Accepted Solution Solved
Reply
Regular Contributor
Posts: 222
Accepted Solution

call symput

Hello everybody,

How to use symput in data step to put a variable's each value of each oberservations into batch of macro variables?

data _null_;

set sashelp.class end=eof;

do until (eof);

call symput('aa'||_n_,sex);

end;

stop;

run;

%put &aa1 &aa2;


Accepted Solutions
Solution
‎05-02-2012 11:03 AM
Valued Guide
Posts: 765

Re: call symput

hi ... you might also consider SYMPUTX to reduce the length of the macro variables, for example ...

data _null_;

set sashelp.class (obs=2);

call symput(cats('aa',_n_),name);

call symputx(cats('bb',_n_),name);

run;

%put |&aa1| |&aa2|;

%put |&bb1| |&bb2|;

123  %put |&aa1| |&aa2|;

|Alfred  | |Alice   |

124  %put |&bb1| |&bb2|;

|Alfred| |Alice|    

also, the various CAT functions do not give you log messages when concatenating numeric variables such as _N_

CATS applies STRIP to each argument so I don't think it's necessary to add the STRIP function within CATS

View solution in original post


All Replies
Regular Contributor
Posts: 222

Re: call symput

data _null_;

set sashelp.class end=eof;

*do until (eof);

call symput('aa'||left(_n_),sex);

*end;

*stop;

run;

%put &aa1 &aa2;

Super Contributor
Posts: 1,636

Re: call symput

or

data _null_;
set sashelp.class ;
call symputx(cats('aa',strip(_n_)),sex);
run;

%put _user_;

Solution
‎05-02-2012 11:03 AM
Valued Guide
Posts: 765

Re: call symput

hi ... you might also consider SYMPUTX to reduce the length of the macro variables, for example ...

data _null_;

set sashelp.class (obs=2);

call symput(cats('aa',_n_),name);

call symputx(cats('bb',_n_),name);

run;

%put |&aa1| |&aa2|;

%put |&bb1| |&bb2|;

123  %put |&aa1| |&aa2|;

|Alfred  | |Alice   |

124  %put |&bb1| |&bb2|;

|Alfred| |Alice|    

also, the various CAT functions do not give you log messages when concatenating numeric variables such as _N_

CATS applies STRIP to each argument so I don't think it's necessary to add the STRIP function within CATS

Super Contributor
Posts: 1,636

Re: call symput

Thank you Milke! It is good to know.  - Linlin

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1100 views
  • 7 likes
  • 3 in conversation