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

Hi if I have a date set like:

ID COUNT
1 10
2 20
3 25

 

I wish to add new columns to the data set, so the output will be this in a proc print:

A total sum up for the values and then divides with the total with 7.

It should be a code that can be used for new numbers every week - so I cant enter the numbers manually

ID COUNT
1 10
2 20
3 25
TOTALSUM 55
DIVIDED7days 7.85

 

datalines:

data have;
infile datalines dsd;
input ID :$1. COUNT;
datalines;
1,10
2,20
3,25

;

 

1 ACCEPTED SOLUTION

Accepted Solutions
singhsahab
Lapis Lazuli | Level 10
data have;
infile datalines dsd;
input ID :$1. COUNT;
datalines;
1,10
2,20
3,25
;
run;

proc sql;
create table want as 
select * from have
union all
select 'Total_sum' as ID,sum(count) as count  from have
union all
select 'DIVIDED7days' as ID,round(floor(sum(count)/7*100)/100,.01) as count from have;
quit;

@mmea Alternate solution .

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

data have;
infile datalines dsd;
input ID :$1. COUNT;
datalines;
1,10
2,20
3,25
;

proc report data=have;
 columns id count weekly;
 define id/display;
 define count/analysis;
 define weekly/computed noprint;
 compute after;
  line @1 'Totalsum' @10 count.sum 8.2;
  weekly=count.sum/7;
  line @1 'Div7days' @10  weekly 8.2 ;
 endcomp;
run;
ID COUNT
1 10
2 20
3 25
Totalsum    55.00
Div7days     7.86
mmea
Quartz | Level 8

Thank you.

 

is it possible in the same proc report to add a statement that will take the total number of observations in one dataset and divide by the dataset used in this statement here?

 

novinosrin
Tourmaline | Level 20

For total number of observations in one dataset, you can have that value in a macro variable and use that in proc report.

mmea
Quartz | Level 8

Okay - is there a way of doing so, im new to sas.

 

Sp a macro for the total number of observations in a dataset, and then i can divide that with the count_sum in the proc report?

novinosrin
Tourmaline | Level 20

Keep it simple. Get the count of nobs from some other dataset like

proc sql;
 select count(*) into :nobs
 from some_other_dataset;
quit;

%put nobs=&nobs; /*write the value of nobs in log*/

and then use the macro variable nobs whereever you want 

 

singhsahab
Lapis Lazuli | Level 10
data have;
infile datalines dsd;
input ID :$1. COUNT;
datalines;
1,10
2,20
3,25
;
run;

proc sql;
create table want as 
select * from have
union all
select 'Total_sum' as ID,sum(count) as count  from have
union all
select 'DIVIDED7days' as ID,round(floor(sum(count)/7*100)/100,.01) as count from have;
quit;

@mmea Alternate solution .

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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