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

Hi

 

Please help me with below problem. I need to multiply rows based on the value in the field. For example my data like this below:

 

Name Window

Moh    3

Raj     4

 

I would like my output to be mulitplied w..r.t window

 

Name Window

Moh   3

Moh   3

Moh   3

Raj     4

Raj     4

Raj    4

Raj   4

 

I am not able to think how can I approach this problem. Any hints are welcome

1 ACCEPTED SOLUTION

Accepted Solutions
pearsoninst
Pyrite | Level 9
data newdata; 
Window = Window; 
input Name$ Window; 
do i = 1 to Window; 
output; 
end; 
datalines; 
Moh 3 
Raj 4 
; run; Proc Print data = newdata; run;

View solution in original post

6 REPLIES 6
pearsoninst
Pyrite | Level 9
data newdata; 
Window = Window; 
input Name$ Window; 
do i = 1 to Window; 
output; 
end; 
datalines; 
Moh 3 
Raj 4 
; run; Proc Print data = newdata; run;
bnarang
Calcite | Level 5

Thanks a lot. It worked

pearsoninst
Pyrite | Level 9
welcome
David2
Calcite | Level 5

Do you always have to specify the values in "Window"? Can this be modified for the case with lots of names?

pearsoninst
Pyrite | Level 9
Window = Window; it will calculate the number you have specified in the the variable window.
So Moh has 3 window so when do loop start i will take 3 (i = 1 to 3 )with the first obs which is raj and then
i will take 4 (i = 1 to 4 ) and the window value in Raj has 4 . And it will work with lots of names .

David2
Calcite | Level 5

OK thanks,  In the datalines argument Moh and Raj have been specified. Can these be done 'on the fly'?

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
  • 6 replies
  • 1727 views
  • 1 like
  • 3 in conversation