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