BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Charlie
Fluorite | Level 6

Hi, All

I want to create a cross table to summaries favorite before and after test the tasty and put stage 1 and stage 2 together. I have created codes to create the result, but could not report it as follow in rtf file, I am wondering if anyone can help?

 

rtf ouput I want as follow:

 
 

擷取.PNG

 

 

The code as following:

data raw;
input (Subject Stage Before After) ($);
cards;
1 I Like Like
2 II Abit Like
3 I Like Abit
4 II Abit Like
5 I Like Abit
6 II Like Like
7 II Abit Like
8 I Like Dislike
9 II Like Abit
10 I Dislike Like
11 II Abit Dislike
12 I Like ND
;
run;

proc sort data=raw; by Stage; run; data class; format Before $8. After $8.; do Before='Like', 'Abit', 'Dislike', 'ND'; do After='Like', 'Abit', 'Dislike', 'ND'; output; end; end; run; proc format; value $FBefore 'Like'='Like' 'Abit'='A bit like' 'Dislike'='Dislike' 'ND'='Not Done'; value $FAfter 'Like'='Like' 'Abit'='A bit like' 'Dislike'='Dislike' 'ND'='Not Done'; run; proc tabulate data=raw missing classdata=class; format Before $FBefore. After $FAfter.; class Before After/order=data; table After, Before*(N=' ')/misstext='0'; by Stage; run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Charlie
Fluorite | Level 6
Thank you for your advice and code.
However, I still want to "Before" and "After" show the result order as the example, therefore, I have modified my code as following:
data class;
format Stage $8. Before $8. After $8.;
do Stage='I', 'II';
do Before='Like', 'Abit', 'Dislike', 'ND';
do After='Like', 'Abit', 'Dislike', 'ND';
output;
end;
end;
end;
run;

proc format;
value $FStage
'R'='I'
'T'='II';

value $FBefore
'Like'='Like'
'Abit'='A bit like'
'Dislike'='Dislike'
'ND'='Not Done';

value $FAfter
'Like'='Like'
'Abit'='A bit like'
'Dislike'='Dislike'
'ND'='Not Done';
run;

proc tabulate data=raw missing classdata=class;
format Stage $FStage. Before $FBefore. After $FAfter.;
class Stage Before After/order=data;
classlev Stage Before After;
format Before $FBefore.;
table After, Stage* Before*(N=' ')/misstext='0' printmiss;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

I think that instead of BY stage that you want Stage as a class variable in the column expression area. That would require modifying your classdata set to include stage.

 

Or use the PRELOADFMT option instead of class data.

proc tabulate data=raw missing ;
format Before $FBefore. After $FAfter.;
class Before After/order=data preloadfmt;
format before $fbefore.;
class stage;
table After, stage* Before*(N=' ')/misstext='0'
        printmiss;
;
run;
Charlie
Fluorite | Level 6
Thank you for your advice and code.
However, I still want to "Before" and "After" show the result order as the example, therefore, I have modified my code as following:
data class;
format Stage $8. Before $8. After $8.;
do Stage='I', 'II';
do Before='Like', 'Abit', 'Dislike', 'ND';
do After='Like', 'Abit', 'Dislike', 'ND';
output;
end;
end;
end;
run;

proc format;
value $FStage
'R'='I'
'T'='II';

value $FBefore
'Like'='Like'
'Abit'='A bit like'
'Dislike'='Dislike'
'ND'='Not Done';

value $FAfter
'Like'='Like'
'Abit'='A bit like'
'Dislike'='Dislike'
'ND'='Not Done';
run;

proc tabulate data=raw missing classdata=class;
format Stage $FStage. Before $FBefore. After $FAfter.;
class Stage Before After/order=data;
classlev Stage Before After;
format Before $FBefore.;
table After, Stage* Before*(N=' ')/misstext='0' printmiss;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 640 views
  • 0 likes
  • 2 in conversation