DATA Step, Macro, Functions and more

combine several output to form a table

Reply
Super Contributor
Posts: 318

combine several output to form a table

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

 

 

Super User
Posts: 19,822

Re: combine several output to form a table

Posted in reply to fengyuwuzu

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;

Super User
Posts: 11,343

Re: combine several output to form a table

Posted in reply to fengyuwuzu

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.

Super Contributor
Posts: 318

Re: combine several output to form a table

/* 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.

Ask a Question
Discussion stats
  • 3 replies
  • 248 views
  • 1 like
  • 3 in conversation