data have;
format bi_date date9.;
infile datalines;
input ln_no $4.
days_past
bi_date date9.
tot_cnt
stay_current
;
return;
datalines;
1111 12 31Mar2020 1 1
2122 12 31Mar2020 1 1
1244 12 31Mar2020 1 1
3333 44 31Mar2020 1 0
2222 30 31Mar2020 1 0
1111 20 30Apr2020 1 1
2222 20 30Apr2020 1 1
3333 22 30Apr2020 1 1
1111 30 31May2020 1 0
2222 11 31May2020 1 1
3333 45 31May2020 1 0
;run;
proc sql;
create table _01_count as
select 'Current' as lbl_Current,sum(tot_cnt) as Count,
sum(stay_current) as Stayed_Current,
bi_date
from have
group by bi_date
order by bi_date
;quit;
proc transpose data=_01_count out=_01_count_2 let;
id bi_date;
var count Stayed_Current;
by lbl_Current;
run;
Produces this
lbl_Current |
_NAME_ |
31MAR2020 |
30APR2020 |
31MAY2020 |
Current |
Count |
5 |
3 |
3 |
Current |
Stayed_Current |
3 |
3 |
1 |
Desired Result as follows.
lbl_Current |
_NAME_ |
31MAR2020 |
30APR2020 |
31MAY2020 |
Current |
Count |
5 |
3 |
3 |
Current |
Stayed_Current |
60.00% |
100.00% |
33.33% |
Would I need to handle the calculation in the proc sql,proc tab or in the datastep
You can only apply one format at a time to a variable (column) in a table.
Looking at your desired result: Do you really need to create a table using Proc Transpose or are you just after a report?
1. Paste your code using the appropriate icon
2. The expected result looks like a report. Maybe a proc tabulate result. Is this what you want?
3. I cannot understand what the percentages represent.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.