BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

DATA C ;
INPUT ID $ STATE $ CITY $ COUPON $ ;
CARDS ;
101  TEL   HYD    A
101  TEL   WAR   B
101  AP     VIJ      A
101  AP    GUN    B
101  AP    VIZ      B
102  TEL   HYD    B
102  TEL   WAR   A
102  AP    VIJ       B
102  AP   GUN     A
102  AP   VIZ       B     
;

 

By using above dataset how to take frequncey as state wise and city wise final i want to get data like this 

 

 ID      STATE/CITY     A      B

101    AP                     2       4

               GUN             1       1

                VIJ                1       1

                 VIZ               0       2

102     TEL                    2        1

                  HYD            1         1

                  WAR           0          1

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Is STATE/CITY a single variable here?

 

And how is B=4 for ID=101? PLease be more specific about how the desired data set is structured

thanikondharish
Fluorite | Level 6
yes STATE/CITY is same variable .I want state and city keep in one variable
ballardw
Super User

One way is:

 

proc tabulate data=c;
   class id state city coupon;
   table id*(state all=' ')*city,
         coupon=' '*n=' '
         / nocellmerge   misstext='0'
   ;
run;

Proc Tabulate by default will not use any record with a missing value for any of the class variables. So that may need to be checked before use.

 

thanikondharish
Fluorite | Level 6
In this code nocellmerge notworking
thanikondharish
Fluorite | Level 6

i want state and city keep in one variable how will we do?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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