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
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.
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;
@PatrickIt worked out except resulting missing in variable "subj"? strange?
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.
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.
infile 'C:\Users\Maggie\Desktop\data.csv'
You dint add the file extension
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.