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

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

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.

 

 

 

gpv2000
Calcite | Level 5
Thank you very much. I was able to resolve it.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 603 views
  • 0 likes
  • 2 in conversation