11-04-2013 10:11 AM
I am using non-sequential #n line pointer control to read following data, where one observation needs to be created out of three records:
Sequence of variables stored in data set has to be as follows:
input #2 Supplier $ State $
#3 Rate 4. Frequency $
However, how do I change sequence of variables to
11-04-2013 10:16 AM
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.;
11-05-2013 09:50 AM
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 @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?
11-05-2013 09:59 AM
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.
11-04-2013 10:27 AM
Define the variables before the INPUT statement. Probably a good practice anyway.
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