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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 919 views
  • 1 like
  • 2 in conversation