data have;
length ln Status $25. ;
input ln Status Month date9. Curr Due_030 tot;
return;
datalines;
122 Current 01Nov2019 1 0 100
122 Current 30Nov2019 1 0 1
122 Due_030 01Dec2019 0 0 5
122 Due_030 31Dec2019 0 1 2
;run;
The last column is called tot. Is there a way to repeat the top number (in this case 100) on all rows with a column name tot2
I want to get the percentage of tot by tot2 (ie 100/100, 1/100, 5/100)
Below doing what you've been asking for.
data have;
length ln Status $25.;
input ln Status Month date9. Curr Due_030 tot;
return;
datalines;
122 Current 01Nov2019 1 0 100
122 Current 30Nov2019 1 0 1
122 Due_030 01Dec2019 0 0 5
122 Due_030 31Dec2019 0 1 2
;
data want;
set have;
retain tot2;
format pct percent10.2;
if _n_=1 then
tot2=tot;
pct=tot/tot2;
run;
proc print data=want;
run;
Hi @Q1983
Why do you need to create tot2 to calculate percentages?
You can simply do this:
data want;
set have;
format pct percent10.2;
pct=tot/100;
run;
Best,
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.