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

I have a dataset:

 

subjid   include        wk     qtotal  mnchg 

    1            1             1       6          .      

    1            1              8       7         4    

    1            1             12       5         2  

    1            1             16       5         3    

    2           1               8       1         4    

    2            1             12       6         1    

    2            1             16       4         2    

    3            1              1       4         1   

    3            1              8        4        5  

 

I would like the create the same dataset with a new variable, which is the mchg divided by the qtotal of wk 1 multiplied by 100. So for each subject the mnchg would be divided by the qtotal that the received at wk 1 (e.g., ./6, 4/6, 2/6, 3/6 ---each times by 100 for subjid 1)...see below for variable output:

 

subjid   include        wk     qtotal  mnchg perchg

    1            1             1       6          .           .

    1            1              8       7         4        4/6*100

    1            1             12       5         2       2/6*100

    1            1             16       5         3       3/6*100

    2           1               8       1         4           .

    2            1             12       6         1         .

    2            1             16       4         2         .

    3            1              1        4          .         .

    3            1              8        4         5           5/4*100

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

is it ok to assume wk=1 would only occur in the 1st record of each subjid?

 

data have;
input subjid   include        wk     qtotal  mnchg ;
cards;
    1            1             1       6          .      
    1            1              8       7         4    
    1            1             12       5         2  
    1            1             16       5         3    
    2           1               8       1         4    
    2            1             12       6         1    
    2            1             16       4         2    
    3            1              1       4         1   
    3            1              8        4        5  
;
data want;
set have;
by subjid;
retain q;
if first.subjid then call missing(q);
if first.subjid and wk=1 then q=qtotal;
else perchg=mnchg/q*100;
run;

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

is it ok to assume wk=1 would only occur in the 1st record of each subjid?

 

data have;
input subjid   include        wk     qtotal  mnchg ;
cards;
    1            1             1       6          .      
    1            1              8       7         4    
    1            1             12       5         2  
    1            1             16       5         3    
    2           1               8       1         4    
    2            1             12       6         1    
    2            1             16       4         2    
    3            1              1       4         1   
    3            1              8        4        5  
;
data want;
set have;
by subjid;
retain q;
if first.subjid then call missing(q);
if first.subjid and wk=1 then q=qtotal;
else perchg=mnchg/q*100;
run;

 

starz4ever2007
Quartz | Level 8

thanks! Worked perfectly!!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 616 views
  • 1 like
  • 2 in conversation