BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mona4u
Lapis Lazuli | Level 10

I'm running proc report using this code and that's what I got. I'm not able to compute the right percentages. 

Please advise me how I can enhance my code  to get the aimed result 

 

proc report data=QUERIES3;
column SITE_NUMBER numsites percentages;
define SITE_NUMBER/ "Top 3 Sites with highest # issues";
define numsites/ analysis sum "# Open Issues";
define percentages/ computed format=percent9.3;

COMPUTE percentages;
percentages=(numsites/numsites.sum);
endcomp;
rbreak after/ summarize ;
run;

 

Top 3 Sites with highest # issues
# Open Issuespercentages
13507.
16017.
14506.
 20.
 
and that the aimed ressult 
 
Top 3 Sites with highest # issues
# Open Issuespercentages
1350735%
1601735%
1450630%
 20100%
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi: You didn't post all of your code (such as your ODS statements) or any data for people to test with. You refer to numsites correctly as numsites.sum in one place in your compute block, but not in the other.But without seeing your data, it's hard to decide what to recommend.

Is SITE_NUMBER character? If so, it has a default usage of DISPLAY. If it is numeric, then it has a default usage of SUM.

Here's an example using FAKE data of how you need to capture the grand total for NUMSITES into a temporary variable before you start writing report rows. Then you use that temporary variable to generate the calculated percentage. I will post a code example using fake data.

 

title; footnote;
data fakedata;
  infile datalines;
  input site $ numsites;
return;
datalines;
aaa 7
bbb 7
ccc 6
;
run;

proc report data=fakedata;
  column site numsites calcpct;
  define site / display;
  define numsites / sum;
  define calcpct / computed 'Percent' f=percent9.2;
  rbreak after / summarize;
  compute before;
    holdtot = numsites.sum;
  endcomp;
  compute calcpct;
    calcpct = numsites.sum / holdtot;
  endcomp;
run;



cynthia

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

PROC FREQ makes it simple.

 

proc freq data=have;
     tables site_number;
run;
--
Paige Miller
mona4u
Lapis Lazuli | Level 10

It wouldn't give me the result I want 

PaigeMiller
Diamond | Level 26

@mona4u wrote:

It wouldn't give me the result I want 


I can't help you if that's all the information you are going to provide. 

--
Paige Miller
Cynthia_sas
SAS Super FREQ

Hi: You didn't post all of your code (such as your ODS statements) or any data for people to test with. You refer to numsites correctly as numsites.sum in one place in your compute block, but not in the other.But without seeing your data, it's hard to decide what to recommend.

Is SITE_NUMBER character? If so, it has a default usage of DISPLAY. If it is numeric, then it has a default usage of SUM.

Here's an example using FAKE data of how you need to capture the grand total for NUMSITES into a temporary variable before you start writing report rows. Then you use that temporary variable to generate the calculated percentage. I will post a code example using fake data.

 

title; footnote;
data fakedata;
  infile datalines;
  input site $ numsites;
return;
datalines;
aaa 7
bbb 7
ccc 6
;
run;

proc report data=fakedata;
  column site numsites calcpct;
  define site / display;
  define numsites / sum;
  define calcpct / computed 'Percent' f=percent9.2;
  rbreak after / summarize;
  compute before;
    holdtot = numsites.sum;
  endcomp;
  compute calcpct;
    calcpct = numsites.sum / holdtot;
  endcomp;
run;



cynthia

mona4u
Lapis Lazuli | Level 10

I have another question I just want to add the word total to the end 

can you show me how I can do it. 

sorry about that but I'm really new to proc report 

 

Top 3 Sites with highest # issues

# Open Issuespercentages
1350735%
1601735%
1450630%
total 20100%
Cynthia_sas
SAS Super FREQ

Hi:

  You need a COMPUTE AFTER block, the method that I show (a simple assignment statement) will only work if the LENGTH of SITE is $5 or bigger. The changes to the previous program are highlighted in yellow:

 

cynthia

 

compute_after_total.png

mona4u
Lapis Lazuli | Level 10

Thanks so much it's working 

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!

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
  • 7 replies
  • 1050 views
  • 2 likes
  • 3 in conversation