Hello,
I am using non-sequential #n line pointer control to read following data, where one observation needs to be created out of three records:
ROMA TOMATO
FRESHPOINT CA
1.80 DAILY
GREEN BEANS
ORGANICS NC
1.20 WEEKLY
Sequence of variables stored in data set has to be as follows:
data produce.vegetables;
infile vegdata;
input #2 Supplier $ State $
#3 Rate 4. Frequency $
#1 VName;
run;
However, how do I change sequence of variables to
Thanks much,
Dhanashree
If you are concerned about the order variables appear in the dataset for your purpose the easiest would be to place format statements before the input.
Format Supplier $25. Rate 4.0 State $15. Vname $15. Frequency $10.;
Input ....
Ok, using FORMAT statement is good practice and I will use it, however will it resolve issue of reading State variable correctly because it is preceded by Supplier variable which is not fixed length, hence one cannot use column pointer @?
format Supplier $25. Rate 3.1 State $2. VName $15. Frequency $10.;
input #2 Supplier
#3 Rate
#2 State
#1 VName
#3 @6 Frequency;
Reading Frequency with @6 is possible as Rate will always be fixed width 3 with n.n format.
However in INPUT statement, when using #2 State will it not create problem as pointer may not be placed at right column always for every record? Is there any other solution?
FORMAT statements do NOT define the variables other than in the same way that SAS will guess what type of variable to define based on how it is first used. To define the variable you will get better results using LENGTH or ATTRIB statement to clearly define them.
Define the variables before the INPUT statement. Probably a good practice anyway.
data produce.vegetables;
length supplier $20 state $2 rate 8 vname $50 frequency $12 ;
infile vegdata truncover ;
input vname $50. /* Useful to use a format to allow for spaces in the names */
/ Supplier State
/ Rate Frequency
;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.