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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
SilverSkyler
Fluorite | Level 6

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. 

 

%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 WORDDATE.;
RUN;
 
PROC CONTENTS DATA= HypImpt.IowaResidents order=varnum;
RUN;
 
PROC PRINT DATA = HypImpt.IowaResidents;
RUN;

View solution in original post

13 REPLIES 13
PaigeMiller
Diamond | Level 26

I don't see where you have asked a question, or described a problem.

 

Please describe the problem clearly and state the desired result.

--
Paige Miller
SilverSkyler
Fluorite | Level 6

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;

 

Patrick
Opal | Level 21

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.

Patrick_0-1632620396045.png

 

And last but not least: What does the SAS log tell you? Any Warnings or Notes about character conversion, truncation, creation of missings etc?

 

SilverSkyler
Fluorite | Level 6

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. 

 

%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 WORDDATE.;
RUN;
 
PROC CONTENTS DATA= HypImpt.IowaResidents order=varnum;
RUN;
 
PROC PRINT DATA = HypImpt.IowaResidents;
RUN;
Patrick
Opal | Level 21

@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.

SilverSkyler
Fluorite | Level 6

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. 

 

Tom
Super User Tom
Super User

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;
tarheel13
Rhodochrosite | Level 12
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? 

SilverSkyler
Fluorite | Level 6

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 935 views
  • 6 likes
  • 6 in conversation