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

Any idea where I'm making mistake here?

See first obs of data attached to this post.

 

DATA want;
  infile 'C:\Users\Maggie\Desktop\data' delimiter=',';
  input @1 time 1.
        @3 group 1.
		@5 subj 4.
		@10(GH1 PF01-PF10 RP1-RP4 RE1-RE3 SF1
             BP1-BP2 VT1 MH1 MH2 MH3 VT2 MH4 VT3 MH5
             VT4 SF2 GH2 GH3 GH4 GH5) (1.); 
run;

Any hints are appreciated. 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You do not need positions when you have a delimited file, SAS finds the columns through the delimiters on its own.

Since all variables are numbers, also drop the informats from the input.

And also add firstobs=2 to the infile statement so you skip the header line.

 

When reading a delimited file with formats, add a colon before the format to prevent pure formatted input that disregards the delimiters.

View solution in original post

6 REPLIES 6
Patrick
Opal | Level 21

What about:

DATA want;
  infile 'c:\temp\data.csv' delimiter=',' dsd truncover firstobs=2;
  input 
    ( 
      Time Group Subj GH1 PF01 PF02 PF03 PF04 PF05 PF06 PF07 PF08 
      PF09 PF10 RP1 RP2 RP3 RP4 RE1 RE2 RE3 SF1 BP1 BP2 VT1 MH1 MH2 
      MH3 VT2 MH4 VT3 MH5 VT4 SF2 GH2 GH3 GH4 GH5 
    )
    (:best32.)
  ;
run;
Cruise
Ammonite | Level 13

@PatrickIt worked out except resulting missing in variable "subj"? strange?

error.png

Patrick
Opal | Level 21

@Cruise

You're dealing with a simple comma separated list. Use list input and do not use any pointer control (the @) as this messes up things for you. 

http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n0lrz3gb7m9e4rn...

 

Look into: Example 4: Reading Comma-Delimited Data with List Input and an Informat

 

BTW: If you would start using SAS Studio or SAS EG then you could take advantage of import wizards which help you to generate the correct SAS code. 

gauthamk28
Obsidian | Level 7
 infile 'C:\Users\Maggie\Desktop\data.csv' 

You dint add the file extension  

Kurt_Bremser
Super User

You do not need positions when you have a delimited file, SAS finds the columns through the delimiters on its own.

Since all variables are numbers, also drop the informats from the input.

And also add firstobs=2 to the infile statement so you skip the header line.

 

When reading a delimited file with formats, add a colon before the format to prevent pure formatted input that disregards the delimiters.

Tom
Super User Tom
Super User

If you have a delimited file then use the DSD option and do not use column pointers or formatted input.

Your file is simple since all of the variables appear to be numbers.

data want;
  infile "&path/data.csv" dsd dlm=',' firstobs=2 truncover ;
  input Time Group Subj  GH1 PF01-PF10 RP1-RP4 
        RE1-RE3 SF1 BP1 BP2 VT1 MH1-MH3 VT2 MH4 VT3 MH5 VT4 SF2 GH2-GH5
  ;
run;

If your file is more complex, for example with some character variables then you would want to first define the variables using a LENGTH statement before the INPUT statement. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 1099 views
  • 0 likes
  • 5 in conversation