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

/*Hi SAS Forum,

I have posted this same question in another forum and am repeating here too due to urgency of resutls generation.


I am having below dataset.
For variable "income", value 999 means the income of the person is actually $999.
However, for "Age" varaible, the value 999 means the value is unknown or missing. */



Data have;
input income Age;
cards;
100 999
200 25
999 30
;
run;


/*Q: I want to calcualte min, max and mean of these 2 vairables using proc means.
We cannot use other methods but must use proc means for calculating min, max and mean (otherwise
it upsets our original long SAS code).

Answer:

for income, min=100  max=999  mean=433
for Age min=25  max=30  mean=27.5  (because value 999 should be omitted from Age variable)

I attmepted below code, but getting me no where. Could an expert help me.
Thanks, Mirisa*/


%macro any (field);
data want;
set have;

%if &field ="income" %then %do;
proc means data=have;
  var &field;
run;
%end;

%mend any;
%any (income);
%any (Age);

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You should change your data, so that the 999 don't mean "missing".  For example:

 

data want;

set have;

if age=999 then age=.U;

run;

 

Then you can use a simple PROC MEANS:

 

proc means data=want;

var income age;

run;

 

By using a special missing value (.U), you can easily differentiate which values used to be 999, vs. which are missing for some other reason.  And PROC MEANS knows enough to omit any type of missing value from the calculations.

View solution in original post

1 REPLY 1
Astounding
PROC Star

You should change your data, so that the 999 don't mean "missing".  For example:

 

data want;

set have;

if age=999 then age=.U;

run;

 

Then you can use a simple PROC MEANS:

 

proc means data=want;

var income age;

run;

 

By using a special missing value (.U), you can easily differentiate which values used to be 999, vs. which are missing for some other reason.  And PROC MEANS knows enough to omit any type of missing value from the calculations.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 2801 views
  • 2 likes
  • 2 in conversation