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
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.
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.
I really appreciate your help! I thought this worked in the beginning but for some reason, it is not working anymore...not sure why..
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.
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
Sometimes, Friday can't come soon enough. Good luck.
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!..
My tired eyes don't notice anything unusual. Perhaps for clarity in reading the results, change the %PUT statement:
%put **** &AllCodes ****;
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..
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: