BookmarkSubscribeRSS Feed
Curious4
Fluorite | Level 6

 

 

I am trying to do these steps in  this image but my code is not working very much.

Here's what I have

data medicine;
input patient date;


RETAIN date2 date9.;

datalines;
REC PATIENT DATE DATE2
1 1001 01FEB2009
2 1001 02FEB2009
3 1001 04FEB2009
4 1001 06FEB2009
5 1002 17FEB2009
6 1002 18FEB2009
7 1002 19FEB2009
8 1003 12FEB2009
9 1003 16FEB2009
10 1003 19FEB2009
;

I keep getting an error with my retain statement saying:

 172        data medicine;
 173        input patient date date2;
 174        
 175        
 176        RETAIN date2 date9.;
                         ______
                         22
                         201
 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, 
               a missing value, (, -, :, ;, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.  
 
 ERROR 201-322: The option is not recognized and will be ignored.
 

 

9 REPLIES 9
novinosrin
Tourmaline | Level 20

HI @Curious4  I am curious to know why you are formatting the date2 variable in a RETAIN statement? 

Curious4
Fluorite | Level 6
Because thats what the assignment asked me to do in the image I posted.
Curious4
Fluorite | Level 6
"We will create a variable date2 that we RETAIN, format this as dat9. (For printing)"
Reeza
Super User
Those are separate programming steps though. You need both a RETAIN and a FORMAT statement.

retain date2;
format date2 date9.;
Curious4
Fluorite | Level 6
Wondering if my if statement looks right.

data medicine;
input patient date;


retain date2;
format date2 date9.;

if first.patient then date2 = date;
else if not first.patient then date=date2;
else date2=date;
Kurt_Bremser
Super User

Some homework assignments from Prof. Kurt:

  • determine if there is a format option available in a RETAIN statement
  • find a statement that lets you assign a FORMAT to a variable.
  • find the option of an INFILE statement that lets you skip a header line in the data
  • explain the reason for reading only two columns, when three are present in the data
  • see if you can find an informat that lets you read a date value as a SAS date value

😉

Finishing these tasks will advance you a lot towards a better understanding of what's happening here.

ballardw
Super User

Some additional Hints:

Do not place variable names in a DATALINES block.

The first value in your data row is Rec not PatientID (left to right on Input needs to match the data lines)

 

 

Curious4
Fluorite | Level 6
Thats how they did it in the image.
Curious4
Fluorite | Level 6
done. i think
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
  • 2073 views
  • 2 likes
  • 5 in conversation