Hello everyone,
I have an aggregated dataset that I want to expand for further calculation. Does anyone know I could achieve this in data step programming.
Dataset have
data have;
input name $ group $ mo_freq $ value ;
datalines;
wlf_01 actv 1-4 0
wlf_01 actv 5-7 1.15
wlf_01 actv 8-10 1.00
wlf_02 dflt 1-4 0
wlf_02 dflt 5-6 5.15
wlf_02 dflt 7-8 4.25
wlf_02 dflt 9-10 0
wlf_03 prog 1-10 2.23
;
run;
dataset want
name |
group |
mo_freq |
month |
value |
wlf_01 |
actv |
1-4 |
1 |
0.00 |
wlf_01 |
actv |
1-4 |
2 |
0.00 |
wlf_01 |
actv |
1-4 |
3 |
0.00 |
wlf_01 |
actv |
1-4 |
4 |
0.00 |
wlf_01 |
actv |
5-7 |
5 |
1.15 |
wlf_01 |
actv |
5-7 |
6 |
1.15 |
wlf_01 |
actv |
5-7 |
7 |
1.15 |
wlf_01 |
actv |
8-10 |
8 |
1.00 |
wlf_01 |
actv |
8-10 |
9 |
1.00 |
wlf_01 |
actv |
8-10 |
10 |
1.00 |
wlf_02 |
dflt |
1-4 |
1 |
0.00 |
wlf_02 |
dflt |
1-4 |
2 |
0.00 |
wlf_02 |
dflt |
1-4 |
3 |
0.00 |
wlf_02 |
dflt |
1-4 |
4 |
0.00 |
wlf_02 |
dflt |
5-6 |
5 |
5.15 |
wlf_02 |
dflt |
5-6 |
6 |
5.15 |
wlf_02 |
dflt |
7-8 |
7 |
4.25 |
wlf_02 |
dflt |
7-8 |
8 |
4.25 |
wlf_02 |
dflt |
9-10 |
9 |
0.00 |
wlf_02 |
dflt |
9-10 |
10 |
0.00 |
wlf_03 |
prog |
1-10 |
1 |
2.23 |
wlf_03 |
prog |
1-10 |
2 |
2.23 |
wlf_03 |
prog |
1-10 |
3 |
2.23 |
wlf_03 |
prog |
1-10 |
4 |
2.23 |
wlf_03 |
prog |
1-10 |
5 |
2.23 |
wlf_03 |
prog |
1-10 |
6 |
2.23 |
wlf_03 |
prog |
1-10 |
7 |
2.23 |
wlf_03 |
prog |
1-10 |
8 |
2.23 |
wlf_03 |
prog |
1-10 |
9 |
2.23 |
wlf_03 |
prog |
1-10 |
10 |
2.23 |
Key is getting the numeric values from the character variable mo_freq;
data want; input name $ group $ mo_freq $ value ; do month = input(scan(mo_freq,1),best.) to ( input(scan(mo_freq,2),best.)); output; end; datalines; wlf_01 actv 1-4 0 wlf_01 actv 5-7 1.15 wlf_01 actv 8-10 1.00 wlf_02 dflt 1-4 0 wlf_02 dflt 5-6 5.15 wlf_02 dflt 7-8 4.25 wlf_02 dflt 9-10 0 wlf_03 prog 1-10 2.23 ; run;
Key is getting the numeric values from the character variable mo_freq;
data want; input name $ group $ mo_freq $ value ; do month = input(scan(mo_freq,1),best.) to ( input(scan(mo_freq,2),best.)); output; end; datalines; wlf_01 actv 1-4 0 wlf_01 actv 5-7 1.15 wlf_01 actv 8-10 1.00 wlf_02 dflt 1-4 0 wlf_02 dflt 5-6 5.15 wlf_02 dflt 7-8 4.25 wlf_02 dflt 9-10 0 wlf_03 prog 1-10 2.23 ; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.