BookmarkSubscribeRSS Feed
Rohit_R
Obsidian | Level 7

Hi,

 

I have a dataset with variables denoting the statuses for the observations as at a month end. The key variables are 'StatusAtMonthend' and 'DaysAtStatusAtMonthend' which are repeated for each of the month ends going back several years. I want to calculate mean and median for the 'DaysAtStatusAtMonth' variable for each of the statuses in the 'StatusAtMonthend' variable.

 

I created two arrays in a datastep holding all the 'StatusAtMonthEnd' in one array and the 'DaysAtStatusAtMonthend' in another. However, I do not know how to calculate the mean/median in the data step, I think it requires a proc means, but it will be inefficient to write a proc means for each of the month ends for several years.

 

data stats;
set statuses;
array TCs {*} Status2015_01-Status2015_12;
array DaysTC {*} DaysAtStatus2015_01-DaysAtStatus_12;

run;

I want the mean/median days spent in each of the statuses at each of the month ends. 

 

Please can someone point me in the right direction?

Thanks.

(Enterprise Guide 7.1)

8 REPLIES 8
Rohit_R
Obsidian | Level 7
I played around a bit and thought of a way, however I am getting an error 'Too many arguments' for the execute subroutine.

%macro mean_med(dataset, status, DaysAtstatus);
proc means data=&dataset mean median;
class &status;
var &DaysAtStatus;
run;
%mend mean_med;

data stats1;
set stats;
array STs (*) ST2015_01-ST2015_12;
array DaysST (*) DaysAtStatus_2015_01-DaysAtTerritory_2015_12;
do i=1 to 12;
call execute("%mean_med(status1" || "," || STs(i)|| "," DaysST(i)|| ")");
end;
run;

Am I missing something in the call execute code?

Thanks.
Rohit_R
Obsidian | Level 7
Hi Kurt, thank you for your quick replies. After using the single quotes, I am still getting following error message.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE,
GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.

ERROR 253-185: The EXECUTE subroutine call has too many arguments.
Loko
Barite | Level 11

Hello,

 

you have missing || before DaysST(i) in the call execute syntax.

 

Anyway i don't think you will get the desired results with this aproach...

Rohit_R
Obsidian | Level 7
Thanks Loko, could you suggest an alternative?
ballardw
Super User

It would help to give a few example records and what the expected output should be.

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
  • 8 replies
  • 1051 views
  • 6 likes
  • 4 in conversation