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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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