Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a macro variable to scan another macro variable

Status
Not open for further replies.

jorondo

Programmer
Jul 23, 2012
1
CA
I am stuck trying to read a macro variable containing a list of values by using the %scan function to find which list is going to be scanned for a value. Here is an example:

1. I have the following list;
%let list_cci=MI CHF CVD PVD DEM CPD CTDRD PUD MLD diab_wc diab_c P_H RD CAN MSLD MC HIV;

2. Each value of this list is another list, as following:
%let MI=410 412;
%let CHF=39891 40201 40211 4291 40401 40403 40411 40413 40491 40493 4254 4255 4257 4258 4259 428;
...

3. The idea is that I want to scan the list, assign a value to a macro variable, and then use that macro variable to tell sas which list to scan for another value. I need to do this in 2 steps because the variable name (MI, CHF, CVD, etc.) is important. However, when

4. Here is what I have done so far, within 2 %do loops that run from 1 to &i and &j:

%let diagname = &%scan(&list_cci.,&i.);
%put &diagname; /*gives me e.g. &MI */

%let var=%scan(&diagname,&j.); /*--->here I expect it would scan the MI list, because &MI is put in the %scan function*/

%put &var; /* but all I get is the jth value from the &list_cci list... even though %put &diagname; gives me &MI!*/

Any ideas why it would scan the first list when I ask to basically %scan(&MI,&j.)? Any other idea how I could solve this?
 
I am not exactly clear with the requiremnt;
But hopefully it would work fine using call symput instead of using %let in macro code.
I would suggest use a data _NULL_ statement inside that use call symput plain scan function.

sasbuddy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top