BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8
data want;
       infile "&path\sample.csv"
       delimiter = ','
       missover
       firstobs = 2
       DSD 
       lrecl = 32767;
       format IP $15.;
       format date yymmdd10.;
       format time hhmm.;
       format zone $5.;
       format cik $7.;
       format accession $20.;
       format extension $30.;
       format code $3.;
       format size 10.;
       input 
             IP $
             date 
             time 
             zone $
             cik $
             accession $
             extension $
             code $
             size
       ;
run;

What will this code does? Can anyone Explain?

I was trying to replace variable names in the CSV file is this correct and I don't want to use Replace.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The code reads (or tries to read) data from a comma-separated file (csv = Comma Separated Values).

FIRSTOBS=2 means that the first line is skipped.

The multiple FORMAT statements implicitly set lengths for the variables; this is not good practice, a LENGTH statement should be used instead.

Since no informat is set, I suspect that the date and time will not be read correctly (unless the file contains raw SAS date and time values).

data want;
infile
  "&path\sample.csv"
  delimiter = ','
  missover
  firstobs = 2
  dsd
  lrecl = 32767
;
length
  IP $15
  date 8
  time 8
  zone $5
  cik $7
  accession $20
  extension $30
  code $3
  size 8
;
format
  date yymmdd10.
  time hhmm.
  size 10.
;
input 
  IP
  date :yymmdd10. /* use proper informat for the dates found in the file */
  time :hhmm. /* same as above, for times */
  zone
  cik
  accession
  extension
  code
  size
;
run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

The code reads (or tries to read) data from a comma-separated file (csv = Comma Separated Values).

FIRSTOBS=2 means that the first line is skipped.

The multiple FORMAT statements implicitly set lengths for the variables; this is not good practice, a LENGTH statement should be used instead.

Since no informat is set, I suspect that the date and time will not be read correctly (unless the file contains raw SAS date and time values).

data want;
infile
  "&path\sample.csv"
  delimiter = ','
  missover
  firstobs = 2
  dsd
  lrecl = 32767
;
length
  IP $15
  date 8
  time 8
  zone $5
  cik $7
  accession $20
  extension $30
  code $3
  size 8
;
format
  date yymmdd10.
  time hhmm.
  size 10.
;
input 
  IP
  date :yymmdd10. /* use proper informat for the dates found in the file */
  time :hhmm. /* same as above, for times */
  zone
  cik
  accession
  extension
  code
  size
;
run;