1
$\begingroup$

I am trying to display a date in my result after running the below program in SAS. It runs properly but in the sas data table under DOB column I don't get anything except a period .

Below is my code what am I doing wrong?

data sample; 
Input ID name $ Dob;
Format DOB mmddyy10. ; 
datalines;
1 abc 22jan1996
2 xyz 25aug1996
;
run;
Proc print data = sample;
run; 

Also I would like to know what does a period means at the end of this line before the semicolon:

Format DOB mmddyy10. ;
$\endgroup$
1

2 Answers 2

2
$\begingroup$

Try the following:

data sample; 
Input ID name $ Dob;
informat DOB date9. ; 
format DOB mmddyy10. ; 
datalines;
1 abc 22jan1996
2 xyz 25aug1996
;
run;
Proc print data = sample;
run; 

I have added the informat line. The problem with the original code is that you have not told SAS what is the format that DOB will come in. In this case: 22jan1996 is of date9. format, so I added the informat telling SAS that the data will come in this way.

The format DOB line tells SAS to display the data as mmddyy10. which makes 22jan1996 look like 01/22/1996.

Lastly, the . before the ; in the format/informat lines specifies that it is a format type. There are character formats: $8. or numeric formats Best12. etc...

$\endgroup$
0
$\begingroup$

You need to specify data informat to read SAS data. Since there is no informat associated with DOB and this field is treated as a Character in SAS. Then when you specified DOB variable Input ID name $ Dob; its a numeric and hence it appears as missing(.).

You need to add the informat line as below.

data sample; 
Input ID name $ Dob;
informat dob date9.;
Format DOB mmddyy10. ; 
datalines;
1 abc '22jan1996
2 xyz '25aug1996
;
run;
Proc print data = sample;
run; 

Note the use of date9. format to read the SAS date.

Read more SAS date formats: How to display dates correctly?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.