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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

1 REPLY 1
ballardw
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 906 views
  • 1 like
  • 2 in conversation