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

I dont want to write multiple output statements in this code. I wan to write this in few statements.

 

data pa1_;

set pa1;

length  pktpt_std $30 visit $30 ;

do part='A'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='8 HR POST';           visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='12 HR POST';           visit='C1 D1';          output; end;

do part='A'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D2';          output; end;

do part='A'; cyc =1;     pktpt_std='48 HR POST';           visit='C1 D3';          output; end;

do part='A'; cyc =1;     pktpt_std='72 HR POST';           visit='C1 D4';          output; end;

do part='A'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D8';          output; end;

do part='A'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D8';          output; end;

do part='A'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D15';         output; end;

do part='A'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D15';         output; end;

do part='A'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='8 HR POST';           visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='12 HR POST';           visit='C1 D22';         output; end;

do part='A'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D23';         output; end;

do part='A'; cyc =1;     pktpt_std='48 HR POST';           visit='C1 D24';         output; end;

do part='A'; cyc =1;     pktpt_std='72 HR POST';           visit='C1 D25';         output; end;

run;

 

data pb1_;

set pb1;

length   pktpt_std $30 visit $30 ;

do part='B'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='8 HR POST';           visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='12 HR POST';           visit='C1 D1';          output; end;

do part='B'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D2';          output; end;

do part='B'; cyc =1;     pktpt_std='48 HR POST';           visit='C1 D3';          output; end;

do part='B'; cyc =1;     pktpt_std='72 HR POST';           visit='C1 D4';          output; end;

do part='B'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='8 HR POST';           visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='12 HR POST';           visit='C1 D8';          output; end;

do part='B'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D9';          output; end;

do part='B'; cyc =1;     pktpt_std='48 HR POST';           visit='C1 D10';         output; end;

do part='B'; cyc =1;     pktpt_std='72 HR POST';           visit='C1 D11';         output; end;

do part='B'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D15';         output; end;

do part='B'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D15';         output; end;

do part='B'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='8 HR POST';           visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='12 HR POST';           visit='C1 D22';         output; end;

do part='B'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D23';         output; end;

do part='B'; cyc =1;     pktpt_std='48 HR POST';           visit='C1 D24';         output; end;

do part='B'; cyc =1;     pktpt_std='72 HR POST';           visit='C1 D25';         output; end;

run;

 

  data pc1_;

  set pc1;

length   pktpt_std $30 visit $30 ;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D1';          output; end;

do part='C'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D1';          output; end;

do part='C'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D1';          output; end;

do part='C'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D1';          output; end;

do part='C'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D1';          output; end;

do part='C'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D2';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D3';          output; end;

do part='C'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D3';          output; end;

do part='C'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D3';          output; end;

do part='C'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D3';          output; end;

do part='C'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D3';          output; end;

do part='C'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D4';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D5';          output; end;

do part='C'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D5';          output; end;

do part='C'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D5';          output; end;

do part='C'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D5';          output; end;

do part='C'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D5';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D8';          output; end;

do part='C'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D8';          output; end;

do part='C'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D8';          output; end;

do part='C'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D8';          output; end;

do part='C'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D8';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D10';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D12';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D15';          output; end;

do part='C'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D15';          output; end;

do part='C'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D15';          output; end;

do part='C'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D15';          output; end;

do part='C'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D15';          output; end;

do part='C'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D22';         output; end;

do part='C'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D22';         output; end;

do part='C'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D22';         output; end;

do part='C'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D22';         output; end;

do part='C'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D22';         output; end;

do part='C'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D23';         output; end;

do part='C'; cyc =1;     pktpt_std='48 HR POST';           visit='C1 D24';         output; end;

do part='C'; cyc =1;     pktpt_std='72 HR POST';           visit='C1 D25';         output; end;

run;

data pd1_;

set pd1;

length  pktpt_std $30 visit $30 ;

do part='D'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D1';          output; end;

do part='D'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D1';          output; end;

do part='D'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D1';          output; end;

do part='D'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D1';          output; end;

do part='D'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D1';          output; end;

do part='D'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D2';          output; end;

do part='D'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D3';          output; end;

do part='D'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D3';          output; end;

do part='D'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D3';          output; end;

do part='D'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D3';          output; end;

do part='D'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D3';          output; end;

do part='D'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D4';          output; end;

do part='D'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D5';          output; end;

do part='D'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D5';          output; end;

do part='D'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D5';          output; end;

do part='D'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D5';          output; end;

do part='D'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D5';          output; end;

do part='D'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D8';          output; end;

do part='D'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D8';          output; end;

do part='D'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D8';          output; end;

do part='D'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D8';          output; end;

do part='D'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D8';          output; end;

do part='D'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D15';         output; end;

do part='D'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D15';         output; end;

do part='D'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D15';         output; end;

do part='D'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D15';         output; end;

do part='D'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D15';         output; end;

do part='D'; cyc =1;     pktpt_std='PRE-DOSE';               visit='C1 D22';         output; end;

do part='D'; cyc =1;     pktpt_std='5 MIN POST';           visit='C1 D22';         output; end;

do part='D'; cyc =1;     pktpt_std='1 HR POST';           visit='C1 D22';         output; end;

do part='D'; cyc =1;     pktpt_std='2 HR POST';           visit='C1 D22';         output; end;

do part='D'; cyc =1;     pktpt_std='4 HR POST';           visit='C1 D22';         output; end;

do part='D'; cyc =1;     pktpt_std='24 HR POST';           visit='C1 D23';         output; end;

do part='D'; cyc =1;     pktpt_std='POST TREATMENT';       visit='C1 D26';         output; end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@yashraj89 wrote:

I am trying to create dummy data for the subjects I have in the input dataset and it follows  the pattern i have mentioned in the code. 

There only certain combinations, the subject comes to visit only on certain instances so i want to create only certain combinations which i have mentioned in the code. I am dummying the data so i cant use a sql join.

 


Below a way how you could approach this. I can't really see a pattern in Visit which would allow for something simple so you might consider going for some other suitable pattern which you can easily fit into below.

data want;
  do part='A','B','C';
    cyc='1';
    do pktpt_std='PRE-DOSE','5 MIN POST','1 HR POST','2 HR POST','4 HR POST','8 HR POST','12 HR POST','24 HR POST','48 HR POST','72 HR POST';
      output;
    end;
  end;
  stop;
run;

proc print;
run;

 

View solution in original post

9 REPLIES 9
ghosh
Barite | Level 11

Can you explain in pseudo code what you are trying to do. I am findinng it tedious to read your output statements

yashraj89
Obsidian | Level 7

In the attached dataset if the subject has cycle 1 then want the records to ouptut with the following variables .

eg:

 

data pa1_;

set pa1;

length  pktpt_std $30 visit $30 ;

do

part='A';

cyc =1;    

pktpt_std=' PRE-DOSE';              

visit='C1 D1';         

output; end;

 

I have attached the input and output dataset in the post to give an idea to get want i am trying to replicate. 

 

 

ghosh
Barite | Level 11
Please describe your problem and desired output
Tom
Super User Tom
Super User

That doesn't really help. Attaching binary format files is not very friendly. Make a nice simple listing and attach as TEXT using the Insert Code button on the editor.

 

This kind of makes it sound like you don't want to turn one observation into many.  Instead it sounds like you want to set the values of some variables based on the value of others.  Is that what is going on?

Tom
Super User Tom
Super User

Your statements as written are not valid.  Is there a pattern there?  Are you just trying to generate a  record for every combination of part, pktpt_std and visit?  Or are you trying to leave out some combinations? If later which ones and why?

 

Are you really trying to blow up some existing dataset?  Turning each input observation into many output observations?  If so why not just use an SQL join?

 

You could also just read the data from datalines (aka cards) instead of using all of the CODE.  Probably a lot easier to replicate data lines in your editor of choice.

yashraj89
Obsidian | Level 7

I am trying to create dummy data for the subjects I have in the input dataset and it follows  the pattern i have mentioned in the code. 

There only certain combinations, the subject comes to visit only on certain instances so i want to create only certain combinations which i have mentioned in the code. I am dummying the data so i cant use a sql join.

 

 

 

Tom
Super User Tom
Super User

So make a VISIT dataset with the observations and values you want and join it to the list of subjects.

data visits;
  input cyc visit $ .... ;
cards;
1 PRE_DOSE .....
....
;

proc sql;
   create table subjects as select distinct subjid from HAVE;
   create table dummy as select * from subjects,visits;
quit;
Shmuel
Garnet | Level 18

@yashraj89 ,  your code:

data pa1_;
  set pa1;
     length  pktpt_std $30 visit $30 ;
  do;                /* <<< you missed the semicolon */
    part='A';
    cyc =1;    
    pktpt_std=' PRE-DOSE';              
    visit='C1 D1';         
    output; 
  end;
  .... 
run;

Are you adding new observations, with 4 new variables and values, to an existing dataset PA1 ?

 

What variables are in PA1? If you are creating a new dataset you don't need the set statement.

By what condition you add those variables?

 

How many parts you need ? are they 'A' 'B' 'C' 'D' only? 

Does cyc have one fixed value ? cyc=1 - always ?

Does visit allways start with 'C1 D' ? let call it visit prefix.

By what rule you add the suffix number to visit prefix ?

Is pktpt_std value a function of visit suffix ?

 

The shorten writing the code you can use arrays, loops and call execute

or by a macro program using macro variables having list of values and %do loops.

 

 

Patrick
Opal | Level 21

@yashraj89 wrote:

I am trying to create dummy data for the subjects I have in the input dataset and it follows  the pattern i have mentioned in the code. 

There only certain combinations, the subject comes to visit only on certain instances so i want to create only certain combinations which i have mentioned in the code. I am dummying the data so i cant use a sql join.

 


Below a way how you could approach this. I can't really see a pattern in Visit which would allow for something simple so you might consider going for some other suitable pattern which you can easily fit into below.

data want;
  do part='A','B','C';
    cyc='1';
    do pktpt_std='PRE-DOSE','5 MIN POST','1 HR POST','2 HR POST','4 HR POST','8 HR POST','12 HR POST','24 HR POST','48 HR POST','72 HR POST';
      output;
    end;
  end;
  stop;
run;

proc print;
run;

 

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1124 views
  • 0 likes
  • 5 in conversation