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

Hello All,

 

I am trying to automate something here:

 

I have a set of codes that have been defined like this:

 

%let Codes1 = "10000" "10001" "10002" "10003"

%let Codes2 = "20000" "20001" "20002" "20003"

 

%let allCodes = &Codes1. &Codes2. ;

 

I want to create code that automatically updates this macro variable allCodes so that if the user adds more types of codes. For ex, if a user wants to add Code3 like:

%let Codes3= "abc" "xyz" 

 

Then how to update allCodes automatically such that it would now be defined as :

 

%let allCodes = &Codes1. &Codes2. &Codes3.; 

 

I think this would be some combination of using sysfunc and concatenating the variables.

Any ideas would be highly appreciated...

 

Regards,

 

Tina

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

On the one hand, there is nothing "automatic" about it.  SAS will never know what the user entered, or that yout want it appended to AllCodes unless you write a program.

 

On the other hand, the programming is easy:

 

%let AllCodes = &AllCodes &Codes3;

 

As long as &Codes3 exists, the program works.  If the user entered nothing at all, but &Codes3 still exists with a null value, the program still works.

View solution in original post

8 REPLIES 8
Astounding
PROC Star

On the one hand, there is nothing "automatic" about it.  SAS will never know what the user entered, or that yout want it appended to AllCodes unless you write a program.

 

On the other hand, the programming is easy:

 

%let AllCodes = &AllCodes &Codes3;

 

As long as &Codes3 exists, the program works.  If the user entered nothing at all, but &Codes3 still exists with a null value, the program still works.

rosegarden81
Obsidian | Level 7

I really appreciate your help! I thought this worked in the beginning but for some reason, it is not working anymore...not sure why..

Astounding
PROC Star

You might need to elaborate ... start with these options turned on:

 

options mprint symbolgen;

 

Then show the log from the code that doesn't work.

rosegarden81
Obsidian | Level 7

 

Hello there,

 

So now it is working again after I restarted SAS and used different values for Codes1, Codes2 (for testing)!..I have attached the screenshot but yes, it now works. I think I need a break for some time..

 

Apologies for the confusion caused!..

 

Regards,

 

Tina

 

 

sc.PNG

Astounding
PROC Star

Sometimes, Friday can't come soon enough.  Good luck.

rosegarden81
Obsidian | Level 7

Actually, this is what I was referring to. When I run the same SAS as before (without repoening SAS), it is showing a different outcome..Please refer to the screenshot of the SAS log..Any ideas or tips how to avoid this kind of output would be greatly appreciated!..

 

sc2.JPG

Astounding
PROC Star

My tired eyes don't notice anything unusual.  Perhaps for clarity in reading the results, change the %PUT statement:

 

%put **** &AllCodes ****;

rosegarden81
Obsidian | Level 7

Made the change you suggested as seen in this screenshot. Previously, it was taking &Codes1, &Codes2, &Codes3 and &Codes4 but after rerunning the same code, it is putting just &Codes1 and &Codes4 so now it is resolving to just "a" "b" "30000" "40000"..

 

Previously it was correctly resolving to "a" "b" "c" "d" "e" "10000" "20000" "30000" "40000"..

 

The same exact code when run once again gives different results...May be this is just s software bug..

 

 

 

 

sc2.JPG

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 976 views
  • 1 like
  • 2 in conversation