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
;
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 .
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 |
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?
For total number of observations in one dataset, you can have that value in a macro variable and use that in proc report.
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?
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
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 .
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.
Ready to level-up your skills? Choose your own adventure.