SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Macro statements?

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

Macro statements?

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;

 


Accepted Solutions
Solution
‎05-19-2017 04:17 PM
Trusted Advisor
Posts: 1,621

Re: Macro statements?

[ Edited ]
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

View solution in original post


All Replies
Solution
‎05-19-2017 04:17 PM
Trusted Advisor
Posts: 1,621

Re: Macro statements?

[ Edited ]
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

Super Contributor
Posts: 297

Re: Macro statements?

What is the following for?

 

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

Super User
Posts: 10,516

Re: Macro statements?


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.

Super Contributor
Posts: 297

Re: Macro statements?

What is the 'G' for?

Super User
Super User
Posts: 6,502

Re: Macro statements?

Super Contributor
Posts: 297

Re: Macro statements?

Thanks,  I just read through it.

Super User
Super User
Posts: 6,502

Re: Macro statements?

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.
☑ This topic is SOLVED.

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

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