BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SAS_Brizvegas
Fluorite | Level 6

I am trying to make some data less identifiable by using a case/when/then statement so that values beneath $10,000 output as <$10,000. However, SAS errors as "Result of WHEN clause 2 is not the same data type as the preceding results" - i.e., I assume it is a text string and not a numeric value due to the "<" symbol. 

 

Does anyone have any ideas of how to work around this? (Other than letting it equal an extremely specific number and then using formulae in Excel afterwards to target that value).

 

Example code in my PROC SQL statement below

SAS_Brizvegas_0-1665017190774.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Making values display differently is quite often the role of a custom format. Create an appropriate format and assign it when creating output such as with Proc Print, Report or other procedure.

 

A rough example:

proc format;
value mydollar
0 -<10000 = "<$10,000"
10000 - high = [dollar12.]
;

data example;
   input x;
datalines ;
1
100
1900
12345678
;

proc print data=example;
   format x mydollar.;
run;

 

There are many things that can be done with formats. One thing is you can specify a format in different calls using the same data to see the effect. Groups created by formats will be honored by reports, analysis and most graphing activities.

View solution in original post

2 REPLIES 2
ballardw
Super User

Making values display differently is quite often the role of a custom format. Create an appropriate format and assign it when creating output such as with Proc Print, Report or other procedure.

 

A rough example:

proc format;
value mydollar
0 -<10000 = "<$10,000"
10000 - high = [dollar12.]
;

data example;
   input x;
datalines ;
1
100
1900
12345678
;

proc print data=example;
   format x mydollar.;
run;

 

There are many things that can be done with formats. One thing is you can specify a format in different calls using the same data to see the effect. Groups created by formats will be honored by reports, analysis and most graphing activities.

SAS_Brizvegas
Fluorite | Level 6

Thank you very much 🙂 Greatly appreciated!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 576 views
  • 3 likes
  • 2 in conversation