BookmarkSubscribeRSS Feed
fengyuwuzu
Pyrite | Level 9

I run the same codes for different data sets (run 5 times the same macro by changing data set names) and got the following output. Is there a way to output into a table, not 5 separate ones like this?

 

Obs

n

mean

std

median

P50

P55

P60

P65

P70

P75

P80

P85

P90

P95

P98

P99

1

8070

124.494

69.8303

103

103

112

121

133

147

162

182

204

232

274

309

329

 

 

Obs

n

mean

std

median

P50

P55

P60

P65

P70

P75

P80

P85

P90

P95

P98

P99

1

7264

132.550

69.0437

112

112

120

130

142

156

172

190

212

239

278

313

330

 

 

Obs

n

mean

std

median

P50

P55

P60

P65

P70

P75

P80

P85

P90

P95

P98

P99

1

6404

142.296

67.8522

122

122

131

141

154

167

183

199

220

245

283

316

332

 

 

Obs

n

mean

std

median

P50

P55

P60

P65

P70

P75

P80

P85

P90

P95

P98

P99

1

5605

152.690

66.2807

133

133

143

154

165

179

193

210

229

253

290

321

334

 

 

Obs

n

mean

std

median

P50

P55

P60

P65

P70

P75

P80

P85

P90

P95

P98

P99

1

4782

165.087

64.0314

148

148

157

167

179

191

205

220

239

263

297

325

337

 

 

3 REPLIES 3
Reeza
Super User

You can append tables fairly easily, just make sure to give them names that start with the same prefix that isn't used elsewhere.

 

data want;

set table1-table5;

run;

ballardw
Super User

Options abound for something like this. But first I would think about providing identification as to where each row of the data in the combined dataset comes from and which variable was summarized.

 

If the same variable is being summarized from each data set I would be strongly tempted to combine the data sets and use the INDSNAME option on a set statement to add a variable with the source the dataset. Then use that varaible in a Class or By statement in Proc Means/Summary or Univariate.

 

If the VARIABLE is different then it may be easier to create output datasets and append together but again I suggest having information about either the data source, variable or both in the result.

 

We would need to see what your macro code is to make suggestions as to which may be preferable.

fengyuwuzu
Pyrite | Level 9
/* I have 5 variables, and for each one, I want to get the top 6%, 7%, 8%, 9%, 10% data */
%macro percent(var=);
proc univariate data=percent.simple ;
var &var ;
output out=percent pctlpre=P pctlpts= 90 91 92 93 94;
run;

data percent.&var._p90 percent.&var._p91 percent.&var._p92 percent.&var._p93 percent.&var._p94;
if _n_=1 then set percent;
set percent.simple;
p90_flag = &var ge P90;
p91_flag = &var ge P91;
p92_flag = &var ge P92;
p93_flag = &var ge P93;
p94_flag = &var ge P94;
if p90_flag=1 then output percent.&var._p90;
if p91_flag=1 then output percent.&var._p91;
if p92_flag=1 then output percent.&var._p92;
if p93_flag=1 then output percent.&var._p93;
if p94_flag=1 then output percent.&var._p94;
drop P9: ;
run;
%mend percent;

%percent(var=betting_days)  /* run this macro using one variable to generate 5 data sets containing top 6% - 10% data */

%macro print(var=,p=);
proc univariate data=percent.&var._&p noprint;
var &var ;
output out=tmp mean=mean median=median n=n std=std pctlpre=P pctlpts= 60 70 75 80 90 95 98 99;
run;
proc print data=tmp; 
title "&p &var" ;
run;
%mend print;

%print(var=betting_days,p=p90)
%print(var=betting_days,p=p91)
%print(var=betting_days,p=p92)
%print(var=betting_days,p=p93)
%print(var=betting_days,p=p94)

 Above are my macros.

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
  • 3 replies
  • 908 views
  • 1 like
  • 3 in conversation