Data Science Asked by Girish Arora on September 4, 2021
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. ;
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...
Correct answer by Dubs on September 4, 2021
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.
Answered by subhro on September 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP