SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

#n Line Pointer Control

Reply
Contributor
Posts: 73

#n Line Pointer Control

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: 

  1. Supplier (FRESHPOINT)
  2. State (CA)
  3. Rate (1.8)
  4. Frequency (DAILY)
  5. VName (ROMA TOMATO)


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


  1. Supplier
  2. Rate
  3. State
  4. VName
  5. Frequency


Thanks much,

Dhanashree

Super User
Posts: 11,343

Re: #n Line Pointer Control

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 ....

Contributor
Posts: 73

Re: #n Line Pointer Control

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?

Super User
Super User
Posts: 7,050

Re: #n Line Pointer Control

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.

Super User
Super User
Posts: 7,050

Re: #n Line Pointer Control

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;

Ask a Question
Discussion stats
  • 4 replies
  • 370 views
  • 0 likes
  • 3 in conversation