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!

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