Hello:
I tried to import a '.csv' file into SAS. I found some codes from the previous programmer as the list below. I have some questions:
1. Why use "informat" first then "format" statement? I tried to just use the "format" statement. I don't see any difference.
2. After the file was imported, I found the order of the columns has been changed. It changed to "JL Rating1 Rating2 Rating3 Rating4 RHSC HTLC LRC VS". Due to the rating is corresponded to its previous column name, how to keep the order the same as input order "JL $ RHSC $ Rating1 $ HTLC $ Rating2 $ LRC $ Rating3 $ VS $ Rating4 $"?
Thanks.
Y
data test;
infile test MISSOVER DSD firstobs=2;
informat JL $22. ;
informat rating1 $32. ;
informat rating2 $18. ;
informat rating3 $100. ;
informat rating4 $12. ;
format JL $22. ;
format rating1 $32. ;
format rating2 $18. ;
format rating3 $100. ;
format rating4 $12. ;
input JL $ RHSC $ Rating1 $ HTLC $ Rating2 $ LRC $ Rating3 $ VS $ Rating4 $;
run;
The appearance for the code makes me believe that may have been generated by proc import.
With simple character variables as long as the length of the variable is set before reading with either informat, format or attrib statement there isn't much difference. However for things such as Date, Datetime or Time variables you would have significantly different behavior as if SAS does not know how to read one of those then applying the format will likely result in something quite different.
Consider these two reads:
data example; input date; format date date9.; datalines; 01012017 ; run; data example2; informat date mmddyy8.; input date; format date date9.; datalines; 01012017 ; run;
The appearance for the code makes me believe that may have been generated by proc import.
With simple character variables as long as the length of the variable is set before reading with either informat, format or attrib statement there isn't much difference. However for things such as Date, Datetime or Time variables you would have significantly different behavior as if SAS does not know how to read one of those then applying the format will likely result in something quite different.
Consider these two reads:
data example; input date; format date date9.; datalines; 01012017 ; run; data example2; informat date mmddyy8.; input date; format date date9.; datalines; 01012017 ; run;
Also, in answer to your other question, the informat and format statements, being before the input statement, control the order of the variables in the resulting file and it works from top to bottom the first time a variable is used. So, all of the variables that you had informats for will be the first variables in your resulting file, followed by those that weren't mentioned in your combination of informat and format statements.
Art, CEO, AnalystFinder.com
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.