BookmarkSubscribeRSS Feed
EC189QRW
Obsidian | Level 7

Dear All,

I've already created a Temp dataset from proc tabulate procedure show as follows, Can i use any Proc procedures to return the Temp datasets back into the original table created by Proc tabulates?  

Any advice to do it?

Thank you all.

Eric

step1:

proc tabulate data=sashelp.class out=temp;
class age sex;
table age='',sex=''*N='';
run; 

temp datasets looks like this

temp.jpg

step2:

proc XXX data=temp;run;

 I am looking for the results like this

target.jpg

 

 

 

6 REPLIES 6
ed_sas_member
Meteorite | Level 14

Hi @EC189QRW 

Please try PROC TABULATE:

proc transpose data=temp out=want (drop=_:);
	var N;
	by age;
	id sex;
run;

 

NB: you could also directly use a PROC REPORT:

proc report data=sashelp.class out=want;
	column age sex;
	define age / group '';
	define sex / across '';
run;

Best,

EC189QRW
Obsidian | Level 7

hi there, thank you for your quick reply. I found the transpose procedure doesn't work when the categorical variable have more than 2 different types.

data class; set sashelp.class; if height<=55 then h='01 L'; else if height<=60 then h='02 M'; else h='03 H'; run;

proc tabulate data=class out=temp; class age sex h; table age='',h=''*N=''; run; 

 1.jpg

proc transpose data=temp out=want (drop=_:); var N; by age; id h; run; proc print data=want;run;

2.jpg

ed_sas_member
Meteorite | Level 14

Hi @EC189QRW 

Could you pease post your log?

Here is what I get when I run the code:

data class;
	set sashelp.class;

	if height<=55 then
		h='01 L';
	else if height<=60 then
		h='02 M';
	else
		h='03 H';
run;

proc tabulate data=class out=temp;
	class age sex h;
	table age='', h=''*N='';
run;

proc transpose data=temp out=want (drop=_:);
	var N;
	id h;
	by age;
run;

proc print data=want;

Capture d’écran 2020-07-06 à 10.47.17.png

 Best,

EC189QRW
Obsidian | Level 7
Here is the log . I think there might be some problem with my SAS base.
NOTE: Additional host information:

X64_10PRO WIN 10.0.18362 Workstation

NOTE: SAS initialization used:
real time 2.57 seconds
cpu time 1.99 seconds

1 data class;
2 set sashelp.class;
3
4 if height<=55 then
5 h='01 L';
6 else if height<=60 then
7 h='02 M';
8 else
9 h='03 H';
10 run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds


11 proc tabulate data=class out=temp;
NOTE: Writing HTML Body file: sashtml.htm
12 class age sex h;
13 table age='', h=''*N='';
14 run;

NOTE: There were 19 observations read from the data set WORK.CLASS.
NOTE: The data set WORK.TEMP has 9 observations and 6 variables.
NOTE: PROCEDURE TABULATE used (Total process time):
real time 0.64 seconds
cpu time 0.43 seconds


15 proc transpose data=temp out=want (drop=_:);
16 var N;
17 id h;
18 by age;
19 run;

NOTE: There were 9 observations read from the data set WORK.TEMP.
NOTE: The data set WORK.WANT has 6 observations and 1 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds


20 proc print data=want;
21

NOTE: There were 6 observations read from the data set WORK.WANT.
NOTE: PROCEDURE PRINT used (Total process time):
real time 12.30 seconds
cpu time 0.61 seconds

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 2235 views
  • 2 likes
  • 2 in conversation