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

Hi, all:

 

I have a macro statement created by a previous coworker.   Could anyone explain what the "call symputx" part and the "if" condition after "call symputx" are for?  Thanks.

 

Y

 

%macro list(lib,sect);

     

      data &sect.c;

            set &sect.a(rename=(name=name_sup));

 

            stabb=scan(name_sup,1,"_");

      run;

 

      data _null_;

            set &sect.c end=eof;

            by name_sup;

 

            j+1;

 

            call symputx("name"||trim(left(put(j,8.))),name_sup,'G');

            call symputx("stabb"||trim(left(put(j,8.))),stabb,'G');

            if eof then call symputx("count_state",j,'G');

      run;

 

%mend list;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if eof

 

tests when you have reached the very last observation of the SAS data set you are processing

 

call symputx

 

 

creates a global macro variable named "count_state" from the value of the data set variable j in that last observation

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26
if eof

 

tests when you have reached the very last observation of the SAS data set you are processing

 

call symputx

 

 

creates a global macro variable named "count_state" from the value of the data set variable j in that last observation

--
Paige Miller
ybz12003
Rhodochrosite | Level 12

What is the following for?

 

call symputx("name"||trim(left(put(j,8.))),name_sup,'G');

ballardw
Super User

@ybz12003 wrote:

What is the following for?

 

call symputx("name"||trim(left(put(j,8.))),name_sup,'G');


creating a series macro variables

Name1 , Name2, Name3 etc holding the values for variable Name_sup for each record in the input data set.

ybz12003
Rhodochrosite | Level 12

What is the 'G' for?

ybz12003
Rhodochrosite | Level 12

Thanks,  I just read through it.

Tom
Super User Tom
Super User
You need to use the 'G' option to have the macro variables created as GLOBAL instead of LOCAL. Otherwise if the macro variables are not already defined then they will be created as LOCAL to the utility macro and thus disappear when the macro finishes running. Making them GLOBAL is one way to make sure the values are available later in your program after the macro has finished.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1285 views
  • 4 likes
  • 4 in conversation