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

sub     GRP     Fruit     Name

01         B        apple       NAVEEN

01         B        grape       SURESH

01         B        guava      BABU

01         B        berry        PAUL

02         C        kiwi          NAVEEN

02         C        p-apple    BABU

02         C        orange     AYESHA

03         A        apple        SURESH

03         A       Tamota       BABU

03         A        orange       SRI

03         A        grape         NAVEEN

04         B        apple        SRI

04         B        kiwi           AYESHA

04         B        orange      BABU

04         B        p-apple     PAUL

05         C        potato         NAVEEN

05         C        apple        SRI

05         C        orange     SURESH

 

 

OUTPUT should like...

NEW          GRPA          GRPB           GRPC

NAVEEN    count(%)       count(%)       count(%)

apple          count(%)       count(%)       count(%)

kiwi               count(%)       count(%)       count(%)

grape         count(%)       count(%)       count(%)

potato          count(%)       count(%)       count(%)

SURESH         count(%)       count(%)       count(%)

grape            count(%)       count(%)       count(%)

apple              count(%)       count(%)       count(%)

orange            count(%)       count(%)       count(%)

BABU             count(%)       count(%)       count(%)

tamota              count(%)       count(%)       count(%)

orange         count(%)       count(%)       count(%)

PAUL           count(%)       count(%)       count(%)

berry             count(%)       count(%)       count(%)

p-apple         count(%)       count(%)       count(%)

AYESHA         count(%)       count(%)       count(%)

orange          count(%)       count(%)       count(%)

kiwi             count(%)       count(%)       count(%)

SRI               count(%)       count(%)       count(%)

orange          count(%)       count(%)       count(%)

apple          count(%)       count(%)       count(%)

 

initially what i did is  getting the counts of Name using proc freq 

and then Fruit...but i didn't get the desired output..

 

would you please solve this one..

I hope You understand my data....

 

sorry for troubling you by asking again and again this one.actually i didn't get what you are saying and you gave an example which is  not related to my problem..

 

sasuser123123
Quartz | Level 8
Thank you so much....and please give an example for
that one.. I'm getting confused..
sasuser123123
Quartz | Level 8
Please give an example related to my problem
Cynthia_sas
SAS Super FREQ

Hi: Here's an example using SASHELP.CLASS.

percent1.png

 

  The keywords for count and percent with PROC REPORT are N and PCTN. PCTN gives the percent of the grand total. SASHELP.CLASS has 19 observations so you can see that each percent is the number in the cell divided by 19. Then the percent9.2 format causes the multiply by 100 to make the percent value.

 

  If you have 2 "sub groups" named SUB-01 and SUB-02, then you need to have an ACROSS item in your PROC REPORT COLUMN statement. You can nest N and PCTN under the ACROSS item, in this case the SUB variable, as shown below:

percent2.png

 

Since SASHELP.CLASS did not have a variable called SUB, I made one. SUB-01 group still has 19 observations, but SUB-02 value only has 13 observations. The percents for SUB-01 will be calculated by dividing by 19 and the percents for SUB-02 will be calculated by dividing by 13.

 

  As you can see, the default behavior of PROC REPORT is to give 1 statistic per column. You CAN manipulate the values to make a new character variable that combines N and PCTN into 1 value like this 19 (100.00%), but that is something you would do AFTER you get a program similar to the above program working and that is the technique I show using COMPUTE blocks in my Creating Complex Reports paper that I referenced in my previous posting.

 

Cynthia

sasuser123123
Quartz | Level 8

sub GRP Fruit Name

01 B apple NAVEEN

01 B grape SURESH

01 B guava BABU

01 B berry PAUL

02 C kiwi NAVEEN

02 C p-apple BABU

02 C orange AYESHA

03 A apple SURESH

03 A Tamota BABU

03 A orange SRI

03 A grape NAVEEN

04 B apple SRI

04 B kiwi AYESHA

04 B orange BABU

04 B p-apple PAUL

05 C potato NAVEEN

05 C apple SRI

05 C orange SURESH





OUTPUT should like...

NEW GRPA GRPB GRPC

NAVEEN count(%) count(%) count(%)

apple count(%) count(%) count(%)

kiwi count(%) count(%) count(%)

grape count(%) count(%) count(%)

potato count(%) count(%) count(%)

SURESH count(%) count(%) count(%)

grape count(%) count(%) count(%)

apple count(%) count(%) count(%)

orange count(%) count(%) count(%)

BABU count(%) count(%) count(%)

tamota count(%) count(%) count(%)

orange count(%) count(%) count(%)

PAUL count(%) count(%) count(%)

berry count(%) count(%) count(%)

p-apple count(%) count(%) count(%)

AYESHA count(%) count(%) count(%)

orange count(%) count(%) count(%)

kiwi count(%) count(%) count(%)

SRI count(%) count(%) count(%)

orange count(%) count(%) count(%)

apple count(%) count(%) count(%)



initially what i did is getting the counts of Name using proc freq

and then Fruit...but i didn't get the desired output..



would you please solve this one..

I hope You understand my data....



sorry for troubling you by asking again and again this one.actually i didn't get what you are saying and you gave an example which is not related to my problem..
Cynthia_sas
SAS Super FREQ
Hi:
I can't solve this issue for you. My previous response was directly related to your problem. Where I have SEX, you would use NAME; and where I have AGE, you would use FRUIT; and where I have SUB, you would use GRP. You have to understand what any procedure will give you by default before you start to manipulate the data.

The challenge that I see it in the data as you've posted it is that you show a value in every GRP column for Naveen, for example, but under Apple, Naveen will ONLY have a count and percent under GRP B. So would you want to see 0 (0%) under GRPA and GRPC for Apple? And likewise for Naveen, he only has Grape under GRPA and Kiwi and Potato under GRPC -- so there are NOT counts under the different groups on every row, as you say you want.

To me, this indicates that you don't quite understand what you have or what you want/need to get. Based on the input data you show, your report will have a lot of "blanks" or 0 where a person does not have that Fruit in that SAME GRP.

As another example, Ayesha has Kiwi in Grp B but Naveen has Kiwi in Grp C. Should the percent for Kiwi for these names be the percent based on all Kiwi in all Groups or should Naveen's percent for Kiwi be based on the total of Grp C fruits or the overall Grand Total of all Groups? And should Ayesha's percent for Kiwi be based on the total of Grp B fruits or the overall Grand Total of all Group?

Again, I recommend that you work to 1) get your data read correctly and then 2) understand which Procedure will give you the correct counts and percents you want and then 3) work on getting the "cosmetic" report you want with N (%).

Cynthia
sasuser123123
Quartz | Level 8
Yeah definitely... thank you so much
sasuser123123
Quartz | Level 8
I got all counts and did percentages manually...and concatenate them..
sasuser123123
Quartz | Level 8
And another doubt I've is


If we have input data like.

State
TAMIL NADU
KARNATAKA
ANDHRA
Chennai
Arakkonam
Anantahpur
Vizag
Nellore
Mangalore
Bangalore

I need out put like

State
TAMIL NADU
Chennai
Arakkonam
ANDHRA
anantahpur
Vizag
Nellore
KARNATAKA
bangalore
Mangalore
sasuser123123
Quartz | Level 8
Is there any possibilities to get the output like this
Cynthia_sas
SAS Super FREQ

Hi:

  There is always the possibility to get output the way you want -- however, based on what you've posted, I don't think you can create the desired output from the input data you show.

 

The challenge between what you show and what you want is that there's not really enough information or enough context for what you're trying to do to provide any suggestions. Here are my thoughts:

questions_forum.png

 

  Your input data seems to be a jumble of State (TAMIL NADU, KARNATAKA and ANDHRA) combined with cities in one column. But I don't see, given that there's only 1 column in your data, how you can determine which cities go under which states in the output file.

 

  As your input data stands, PROC SORT, PROC SQL, PROC REPORT, and PROC TABULATE will NOT give you what you want with only 1 column and the values jumbled together as they are. Perhaps if your data had a different structure or some kind of other identifier it would be possible. The only way I can see to produce your desired output is for you to manually associate the cities with each state.

 

  Also, this seems to be a new question, and unrelated to the previous postings in this thread. In the future, it's probably better to open a new posting for a new question.

 

Cynthia

PaigeMiller
Diamond | Level 26

@sasuser123123 wrote:

I've a input data like.
State
TAMIL NADU
KARNATAKA
ANDHRA
Chennai
Arakkonam
Anantahpur
Vizag
Nellore
Mangalore
Bangalore

I need out put like

State
TAMIL NADU
Chennai
Arakkonam
ANDHRA
anantahpur
Vizag
Nellore
KARNATAKA
bangalore
Mangalore

Is there any possibilities to get the output like this ..


Yes, you create a new variable and then assign TAMIL NADU a value of 1 in the new variable, Chennai a value of 2 in the new variable, and so on; then sort by the new variable.

--
Paige Miller
sasuser123123
Quartz | Level 8
Actually I'm doing a case study in which I've variables state and cities in input data..and I did some calculations (count& % )for state and cities separately. So now I have variable count_percent along with state and cities .so now I want to merge the data to get the desired out put like
Actually previously I gave the data wrongly.. I'm really sorry for that one

And one more thing is I've different variable names.. I took the different variable names and it's values for better understanding.

Thank you !

State
TAMIL NADU
KARNATAKA
ANDHRA
chennai
arakkonam
anantahpur
vizag
nellore
mangalore
bangalore

I need out put like

State
TAMIL NADU
chennai
arakkonam
ANDHRA
anantahpur
vizag
nellore
KARNATAKA
bangalore
mangalore

Cynthia_sas
SAS Super FREQ
Hi:
I'm sorrry, I do not understand the structure of your data and your variables. Showing a list of combined City/State names without the other variables is not useful. Your description doesn't give anyone data that they could use in a program. It seems like you expect the people who are reading this to make up the same count and percent numbers that you've calculated. And it seems like you expect people to figure out what the structure of your data is. You say that you have variables named City, State, count and percent, but that's NOT what you show above. You only show one single list of combined cities and states and another list of those same cities and states rearranged. You don't show counts and percents anywhere. But the count for each city is going to be 1 and it is impossible to know how you have calculate percent -- do you calculate percent as the city count divided by the count of ALL the cities or do you calculate percent for each city by the count of all the cities in the SAME state?

As I showed in my previous examples, PROC REPORT will calculate count and percents for you -- generally based on the percent of the grand total, but can also calculate percent of a group total. But without better data examples from you, it is hard to do more than provide general advice.

Cynthia
sasuser123123
Quartz | Level 8
Hello ma'am,
A dataset has a variable AGE that contains values..I want the count, percentages of age of different conditions like <65,>=65,<75,>=75...Of course I know we will get output using proc freq..
But output should like,
Age TRT1. TRT2
<65. n(%). n(%)
>=65. "
<75. "
>=75. "
I got the count and percentages
But how do we get the different conditions in dataset..
Thankyou.

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!

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
  • 52 replies
  • 19706 views
  • 3 likes
  • 6 in conversation