LIBNAME HypImpt "/home/u59445223/BIOS 6680/Hypertension Study/Data/2_Import";
DATA HypImpt.IowaResidents;
INFILE "/home/u59445223/BIOS6680/Hypertension Study/Data/1_Source/IowaResidents.csv" DSD;
INPUT SSN :$11.
Initials :$4.
City :$20.
State :$4.
ZipCd
Sex :$6.
Ethnicity :$12.
Race :$5.
BirthDt MMDDYY10.;
FormattedDate = BirthDt;
FORMAT FormattedDate MMDDYY10.;
Format BirthDt MMDDYY10.;
RUN;
PROC CONTENTS DATA= HypImpt.IowaResidents order=varnum;
RUN;
PROC PRINT DATA = HypImpt.IowaResidents;
LIBNAME HypImpt CLEAR;
RUN;
Thank you for taking the time to respond . I was getting a LIBNAME error but everything else was reading in (I think I needed to fix something with the pathway). The program is displaying correctly now and I am using Wordate to format the date. Thanks again.
I don't see where you have asked a question, or described a problem.
Please describe the problem clearly and state the desired result.
I am reading from a csv file into SAS. The data set to create is IowaResidents into the HypImpt library. All observations are displaying in SAS as they should except for the BirthDt observations. I am only output one digit per BirthDt observation. I was hoping it would output in the format MMDDYY10. However, it does not. Only one single digit is seen in the Results window per BirthDt. Please help. What is wrong with my code please?
LIBNAME HypImpt "/home/u59445223/BIOS 6680/Hypertension Study/Data/2_Import";
DATA HypImpt.IowaResidents;
INFILE"/home/u59445223/BIOS6680/Hypertension Study/Data/1_Source/IowaResidents.csv" DSD;
INPUT SSN :$11.
Initials :$4.
City :$20.
State :$4.
ZipCd
Sex :$6.
Ethnicity :$12.
Race :$5.
BirthDt MMDDYY10.;
FormattedDate = BirthDt;
FORMAT FormattedDate MMDDYY10.;
Format BirthDt MMDDYY10.;
RUN;
PROC CONTENTS DATA= HypImpt.IowaResidents order=varnum;
RUN;
PROC PRINT DATA = HypImpt.IowaResidents;
LIBNAME HypImpt CLEAR;
RUN;
If your unformatted variable BirthDt doesn't show a number somewhere in the range as below then you need to a) verify in your csv that the birthdate values are in the column from where you read them in your code, b) that you use the correct configuration in your infile statement (like: dsd dlm=',' truncover) and c) that you are using the correct informat for the date strings in the .csv.
And last but not least: What does the SAS log tell you? Any Warnings or Notes about character conversion, truncation, creation of missings etc?
Thank you for taking the time to respond . I was getting a LIBNAME error but everything else was reading in (I think I needed to fix something with the pathway). The program is displaying correctly now and I am using Wordate to format the date. Thanks again.
@SilverSkyler I guess your answer means "problem solved". If so then please mark the answer that helped you most as solution. Also: I really would add TRUNCOVER to your infile statement. With the default being FLOWOVER most likely undesired things would happen should there ever be columns missing in a line of your source data.
Hi Patrick:
I'm a newb here. This is literally my first time posting in this community forum. I do not know how to pin answers or responses. However, I am very grateful for all the help given. I will try TRUNCOVER. Thanks.
Add the TRUNCOVER option to your INFILE statement. This is critical if any line is missing one or more values. But it is doubly critical with your program because you forgot the colon modifier in front of the last informat in your INPUT statement. So if the text in the data uses single digits for month or day then there will not be 10 characters left on the line for the INPUT statement to read. With the default FLOWOVER setting it will jump to the next line. With usually unwanted MISSOVER option it will set those short values to MISSING (as the name implies). With TRUNCOVER the short values are used so date strings with single digit month or day values will be interpreted properly.
Also ZIPCODE values are NOT numbers. What if some of the records have ZIP+4 values? What if some are from countries where postal codes include letters?
INFILE "&CourseRoot/Hypertension Study/Data/1_Source/IowaResidents.csv" DSD truncover;
INPUT
SSN :$11.
Initials :$4.
City :$20.
State :$4.
ZipCd :$10.
Sex :$6.
Ethnicity :$12.
Race :$5.
BirthDt :MMDDYY10.
;
FORMAT BirthDt WORDDATE.;
RUN;
Thank you.
Thank you.
data work.shoes;
infile "/folders/myfolders/import/shoes.csv"
delimiter = ","
missover
dsd
firstobs=2;
informat Region $50.;
informat Product $50.;
informat Subsidiary $50.;
informat Stores best12.;
informat Sales dollar12.;
informat Inventory dollar12.;
informat Returns dollar12.;
format Region $50.;
format Product $50.;
format Subsidiary $50.;
format Stores best12.;
format Sales dollar12.;
format Inventory dollar12.;
format Returns dollar12.;
input
Region $
Product $
Subsidiary $
Stores
Sales
Inventory
Returns;
run;
proc print data=work.shoes (obs=6) noobs;
run;
Can you post a screenshot of the csv data? Also, don't you need dlm=',' if it's a csv?
Thank you for your help.
Please post the complete log of the DATA step; use this button to open a box into which to paste the log text:
It is fixed now. Thanks all for your assistance.
%LET CourseRoot = /home/u59445223/BIOS 6680;
LIBNAME HypImpt "&CourseRoot/Hypertension Study/Data/2_Import";
DATA HypImpt.IowaResidents;
INFILE "&CourseRoot/Hypertension Study/Data/1_Source/IowaResidents.csv" DSD;
INPUT SSN :$11.
Initials :$4.
City :$20.
State :$4.
ZipCd
Sex :$6.
Ethnicity :$12.
Race :$5.
BirthDt MMDDYY10.;
FORMAT BirthDt MMDDYY10.;
RUN;
PROC CONTENTS DATA= HypImpt.IowaResidents order=varnum;
RUN;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.