how to import the following with datalines

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

how to import the following with datalines

12/09/2010;Houston; TX; 77077

10/16/2009;Houston; TX; 77040

9/18/2009;Katy; TX; 77450

I have used the following:

data pd;

infile cards;

informat date mmddyy10.;

input date mmddyy10. address $12. area  $2. Pin ;

format date mmddyy10.;

cards4;      

12/09/2010;Houston; TX; 77077

10/16/2009;Houston; TX; 77040

9/18/2009;Katy; TX; 77450

;;;;


Accepted Solutions
Solution
‎07-12-2014 07:57 PM
Super User
Super User
Posts: 7,050

Re: how to import the following with datalines

Posted in reply to venkatnaveen

You should be able to add colon modifiers in front of the formats in your INPUT statement to prevent SAS from trying to read the delimiters between the fields as part of the values.

Personally I usually just use a list mode input INPUT statement when reading data in a list mode (lists delimited with semi-colons, tabs or commas are just like lists delimited with spaces).  Set the definitions of your variables with a LENGTH or ATTRIB statement instead of assuming SAS will figure it out from the format that you used on the INPUT statement.  If any fields require a special informat to be read properly then attach it to them with an INFORMAT or ATTRIB statement.

data pd;

  infile cards dlm= ';' dsd truncover;

  length date 8 address $12 area $2 Pin 8;

  informat date mmddyy10.;

  format date mmddyy10.;

  input date address area Pin ;

cards4;     

12/09/2010;Houston; TX; 77077

10/16/2009;Houston; TX; 77040

9/18/2009;Katy; TX; 77450

;;;;

View solution in original post


All Replies
Valued Guide
Posts: 2,177

Re: how to import the following with datalines

Posted in reply to venkatnaveen

Try the following:

data pd;

infile cards dlm= ';' dsd;

informat date mmddyy10.;

input date  address :$12. area :  $2. Pin ;

format date mmddyy10.;

cards4;      

12/09/2010;Houston; TX; 77077

10/16/2009;Houston; TX; 77040

9/18/2009;Katy; TX; 77450

;;;;

Frequent Contributor
Posts: 89

Re: how to import the following with datalines

thanks peter

Frequent Contributor
Posts: 89

Re: how to import the following with datalines

Posted in reply to venkatnaveen

Hi peter,

Thanks,

But,I am not getting result.

Super User
Posts: 10,035

Re: how to import the following with datalines

Posted in reply to venkatnaveen

add   RUN;   at the end of code.

Valued Guide
Posts: 2,177

Re: how to import the following with datalines

Posted in reply to venkatnaveen

If you show us a saslog we might be able to help

Solution
‎07-12-2014 07:57 PM
Super User
Super User
Posts: 7,050

Re: how to import the following with datalines

Posted in reply to venkatnaveen

You should be able to add colon modifiers in front of the formats in your INPUT statement to prevent SAS from trying to read the delimiters between the fields as part of the values.

Personally I usually just use a list mode input INPUT statement when reading data in a list mode (lists delimited with semi-colons, tabs or commas are just like lists delimited with spaces).  Set the definitions of your variables with a LENGTH or ATTRIB statement instead of assuming SAS will figure it out from the format that you used on the INPUT statement.  If any fields require a special informat to be read properly then attach it to them with an INFORMAT or ATTRIB statement.

data pd;

  infile cards dlm= ';' dsd truncover;

  length date 8 address $12 area $2 Pin 8;

  informat date mmddyy10.;

  format date mmddyy10.;

  input date address area Pin ;

cards4;     

12/09/2010;Houston; TX; 77077

10/16/2009;Houston; TX; 77040

9/18/2009;Katy; TX; 77450

;;;;

Frequent Contributor
Posts: 89

Re: how to import the following with datalines

Thanks for talking time for resolving.

Thanks Tom.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 333 views
  • 0 likes
  • 4 in conversation