I do not use sas often these days but I need to create a macro that looks for a variables with certain suffix , eg: lesion_decod, so I want to look for _decod variables and if it is present ,I want to compute its data.
If that variable has value of 0 I want it to display as 'No'. The dataset could have multiple _decod variables.
Any suggestions?
One option is if you "know" that you want to use a suffix to search on when naming the variables then make it a prefix. SAS has lists that will use prefixes but not suffixes. And just how many variables are we talking about? 3? 150? As this process goes forward will the list of "decode" variables stay the same?
It may help to show or describe what you mean by "compute its data". Depending on what you are actually doing there could be different approaches.
A custom format can display just about anything you want for an existing value. Example:
proc format; value yn 1='Yes' 0='No' ; run; data example; input x y z; datalines; 1 1 1 1 1 0 1 0 0 0 0 0 ; proc print data=example; format x y z yn.; run;
If you don't define a value in the format for 1, or other numeric values, then a best. type format will be applied to display the numeral(s).
You do need to make sure the custom format is available in the session by either running the proc format code or creating a permanent library with the format and using options to tell SAS to look in the library for your format.
One option is if you "know" that you want to use a suffix to search on when naming the variables then make it a prefix. SAS has lists that will use prefixes but not suffixes. And just how many variables are we talking about? 3? 150? As this process goes forward will the list of "decode" variables stay the same?
It may help to show or describe what you mean by "compute its data". Depending on what you are actually doing there could be different approaches.
A custom format can display just about anything you want for an existing value. Example:
proc format; value yn 1='Yes' 0='No' ; run; data example; input x y z; datalines; 1 1 1 1 1 0 1 0 0 0 0 0 ; proc print data=example; format x y z yn.; run;
If you don't define a value in the format for 1, or other numeric values, then a best. type format will be applied to display the numeral(s).
You do need to make sure the custom format is available in the session by either running the proc format code or creating a permanent library with the format and using options to tell SAS to look in the library for your format.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.