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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 439 views
  • 0 likes
  • 2 in conversation