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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
MikeZdeb
Rhodochrosite | Level 12

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

4 REPLIES 4
Mike_Davis
Fluorite | Level 6

data _null_;

set sashelp.class end=eof;

*do until (eof);

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

*end;

*stop;

run;

%put &aa1 &aa2;

Linlin
Lapis Lazuli | Level 10

or

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

%put _user_;

MikeZdeb
Rhodochrosite | Level 12

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

Linlin
Lapis Lazuli | Level 10

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

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
  • 3877 views
  • 7 likes
  • 3 in conversation