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

Hi All, 

 

Too look, it maybe simple. But i am stuck with this. Kindly help.

 

Input Data set:

 

Data country;
input country $ siteid;
cards;
IN 101
IN 101
IN 102
US 101
US 101
US 101
US 101
US 102
US 102
US 103
EU 105
EU 105
EU 105
EU 106
;

 

Required Output:

 

 

Country Siteid Total Percent
EU 105 3 21.43
EU 106 1 7.14
EU All 4 28.57
IN 101 2 14.29
IN 102 1 7.14
IN All 3 21.43
US 101 4 28.57
US 102 2 14.29
US 103 1 7.14
US All 7 50.00

  
  

 

Currently i am using below code. It is not giving right ouput.

 

data country1;
set country;
output;
siteid = "All";
output;
siteid = "All";
run;

proc sort data = country1;
by country;
run;

proc freq data = country;
tables country * siteid / out = country_1 ;
by country;
run;

 

Thanks,

RS

1 ACCEPTED SOLUTION

Accepted Solutions
RJY
Fluorite | Level 6 RJY
Fluorite | Level 6

Perfect. Again thanks a lot for your quick response. very helpful 🙂

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not a transpose issue by the way.

 

Something like:

proc sql;
create table want as
select country,
siteid,
count(*) as total,
(count(*)/(select count(*) from country))*100 as percent
from country
group by country,
siteid;
quit;

 

RJY
Fluorite | Level 6 RJY
Fluorite | Level 6

Thanks a lot for your quick response. With your code 'All' value is not populating. Temporarily, I am also using proc sql steps for each country separately and appending to one table. But this will be length looking for simple program. 

 

CountrySiteidTotalPercent
EU105321.43
EU10617.14
EUAll428.57
IN101214.29
IN10217.14
INAll321.43
US101428.57
US102214.29
US10317.14
USAll750.00
RW9
Diamond | Level 26 RW9
Diamond | Level 26
proc sql;
 create table want as
 select * 
 from   (
          select country,
                 strip(put(siteid,best.)) as siteid,
                 1 as ord,
                 count(*) as total,
                 (count(*)/(select count(*) from country))*100 as percent
          from   country
          group by country,
                   siteid
          union all
          select country,
                 "All",
                 2 as ord,
                 count(*),
                 (count(*)/(select count(*) from country))*100
          from   country
          group by country)
  order by country,ord;
quit;
RJY
Fluorite | Level 6 RJY
Fluorite | Level 6

Perfect. Again thanks a lot for your quick response. very helpful 🙂

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Would have been nice to mark the actual answer to the question as correct, rather than your response to that Smiley Happy

Ksharp
Super User

Data country;
input country $ siteid;
cards;
IN 101
IN 101
IN 102
US 101
US 101
US 101
US 101
US 102
US 102
US 103
EU 105
EU 105
EU 105
EU 106
;
proc tabulate data=country;
class country siteid;
table country=' '*(siteid all), n='Total' pctn='Percent'
/box='country';
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 6 replies
  • 2973 views
  • 1 like
  • 3 in conversation