BookmarkSubscribeRSS Feed
Nupur20
Calcite | Level 5

I have a data in sas like:

Category              Response

A                         50% - 70%

A                          0%

A                          0%

A                          More than 70%

B                          More than 70%

B                          1% - 49%

B                            0%

B                             0%

B                           50% -70%

I want my result data to look like:

Response                  A                B

0%                          2 (50%)        2 (40%)

1% -49%                   0(0%)         1 (20%)

50%- 70%                 1 (25%)       1 (20%)

More than 70%         1 (25%)         1 (20%)

Explanation of result data:

There are two categories A (=4)and B (=5) and there are four different types of response 0%, 1% -49%, 50% -70% and more than 70%.

In category A, only two out of four responded 0%, thus result is 2 (50%). Similarly in A, on;y one out of four responded 50-70%, thus result is 1 (25%).

Same as B for each response.

I would be grateful for your time reagarding the same.

7 REPLIES 7
Ksharp
Super User

For your situation, I prefer to use proc report.

data temp;
input Category     $     Response & $20.;
cards;
A                         50% - 70%
A                          0%
A                          0%
A                          More than 70%
B                          More than 70%
B                          1% - 49%
B                            0%
B                             0%
B                           50% - 70%
;
run;
options missing=0;
proc report data=temp nowd out=x;
 column response category,(n pctn cate);
 define response/group;
 define category/across ' ';
 define n/noprint ;
 define pctn/ noprint;
 define cate/computed ' ';
 compute cate /char length=10;
  _c4_=cats(_c2_,'(',_c3_*100,'%)');
  _c7_=cats(_c5_,'(',_c6_*100,'%)');
 endcomp;
run;

Ksharp

dhana
Fluorite | Level 6

Thanks to KSharp's idea of using PROC REPORT. Here is one more solution using PROC TABULATE.

PROC FORMAT;

     PICTURE MYPCT LOW-HIGH = '009%)'   (PREFIX="(");

RUN;

OPTIONS MISSING=0;

PROC TABULATE DATA = DSN;

CLASS RESPONSE CATEGORY;

TABLE RESPONSE, CATEGORY*(N='' PCTN<RESPONSE>=' ' *F=MYPCT.);

RUN;

SAS Output.JPG

Though we are getting the expected output, the 0's are not displaying with % sign. Can some one help on how to display 0 along with % sign.

Thanks

Dhanasekaran R

Ksharp
Super User

My code has already achieved that.

Ksharp

dhana
Fluorite | Level 6

Yes I understood your solution worked well. But I just tried the same output with PROC TABULATE except the 0 with % sign everything is working fine.

Can you help how to get this 0 with % sign in my solution.

Thanks

Dhanasekarna R

Ksharp
Super User

I am afraid that you need to pre-process your datasets firstly.

That is to say change the missing value into 0 , then use proc tabulate.

Is there someone can use proc tabulate to get it directly?

Ksharp

Ksharp
Super User

It is very interesting. If I used O to instead of zero ,it worked. If you don't mind this.

data temp;
input Category     $     Response & $20.;
cards;
A                         50% - 70%
A                          0%
A                          0%
A                          More than 70%
B                          More than 70%
B                          1% - 49%
B                            0%
B                             0%
B                           50% - 70%
;
run;



PROC FORMAT;

     PICTURE MYPCT LOW-HIGH = '009%)'   (PREFIX="(")
                          . = '(O%)';

RUN;


 
options missing=O;
PROC TABULATE DATA = temp ;

CLASS RESPONSE CATEGORY;

TABLE RESPONSE, CATEGORY*(N='' PCTN=' ' *F=MYPCT.);

RUN;

Ksharp

dhana
Fluorite | Level 6

Yes I have got O in place of zero. Thanks Ksharp for your idea. Smiley Happy  But that is not an accepted soultion. Smiley Wink. Does some one have any idea ?

Thanks

Dhanasekaran R

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 7 replies
  • 802 views
  • 0 likes
  • 3 in conversation