BookmarkSubscribeRSS Feed
NoorulIyn
Calcite | Level 5

can length statements be used instead of truncover option in raw data sets

10 REPLIES 10
data_null__
Jade | Level 19

Are oranges better than apples?

NoorulIyn
Calcite | Level 5

I am new into SAS and can someone explain this both.Thanks

Tom
Super User Tom
Super User

They are not really even related.

The TRUNCOVER (vs FLOWOVER) option sets how SAS behaves when you read past the end of the line.

The LENGTH option lets you tell SAS what variable to populate with the length of the line.

You could conceivably generate some customized logic using the values of the variables specified by the LENGTH and COLUMN options to control when to move to another line, but 99.9 % of normal data input would not require that.

NoorulIyn
Calcite | Level 5

Thanks !!!

Can you suggest another option for this program used in UE edition to produce sames results without using length statement

data work.sales2;

  length Employee_ID 8 First_Name $ 12

  Last_Name $ 18 Gender $ 1

   Salary 8 Job_Title $ 25

  Country $ 2;

  infile "&path/sales.csv" dlm=',';

  input Employee_ID First_Name $ Last_Name $

  Gender $ Salary Job_Title $ Country $;

run;

How can I get the same result without truncated job_title....

Thanks In Advance.....

Reeza
Super User

Your code is missing reading in the last two variables which is possibly causing some of the issues..

You should also use the DSD option instead of DLM=',' as well as the truncover option.

data work.sales2;

  length Employee_ID $8. First_Name $12.

  Last_Name $18. Gender $.1

   Salary 8. Job_Title $25. Date1 date9. date2 mmddyyyy10.

  Country $2.;

  infile "&path/sales.csv" DSD Truncover;

  input Employee_ID First_Name  Last_Name Gender Salary Job_Title  Country date1 date2;

run;

Reeza
Super User

Without seeing what your data looks like its difficult to say why the job title is being truncated.

Does it have spaces or is it just longer than 25 characters?

NoorulIyn
Calcite | Level 5

v1 length 20 reading the same line

1120102TomZhouM108255Sales MaAU
2120103WilsonDawesM87975Sales MaAU
3120121IrenieElvishF26600Sales ReAU
4120122ChristinNganF27475Sales ReAU
5120123KimikoHotstoneF26190Sales ReAU
6120124LucianDaymondM26480Sales ReAU
7120125FongHofmeistM32040Sales ReAU
8120126SatyakamDennyM26780Sales ReAU
9120127SharrynClarksonF28100Sales ReAU

without length option.....

data csv file

120102,Tom,Zhou,M,108255,Sales Manager,AU,11AUG1973,06/01/1993                 

120103,Wilson,Dawes,M,87975,Sales Manager,AU,22JAN1953,01/01/1978              

120121,Irenie,Elvish,F,26600,Sales Rep. II,AU,02AUG1948,01/01/1978             

120122,Christina,Ngan,F,27475,Sales Rep. II,AU,27JUL1958,07/01/1982            

120123,Kimiko,Hotstone,F,26190,Sales Rep. I,AU,28SEP1968,10/01/1989            

120124,Lucian,Daymond,M,26480,Sales Rep. I,AU,13MAY1963,03/01/1983             

120125,Fong,Hofmeister,M,32040,Sales Rep. IV,AU,06DEC1958,03/01/198

Tom
Super User Tom
Super User

The LENGTH statement is a method for defining your variables. You can also use the ATTRIB statement.

Once you have defined your variables the INPUT statement is much easier to write.  In fact you can even use variable lists as in the example below.

The TRUNCOVER option will allow the INPUT statement to handle lines when the last value is empty, or even if there are not enough delimiters on the line.  For example see how I changed the next to last line of input data.

Your example data looks like a normal CSV file. So you should use the DSD option.

data want ;

  infile cards dsd truncover ;

  length

     Employee_ID 8

     First_Name $ 12

     Last_Name $ 18

     Gender $ 1

     Salary 8

     Job_Title $ 25

     Country $ 2

     Date1 8

     Date2 8

  ;

  informat date1 date9. date2 mmddyy10. ;

  format date1 date2 yymmdd10.;

  input Employee_ID -- Date2 ;

cards;

120102,Tom,Zhou,M,108255,Sales Manager,AU,11AUG1973,06/01/1993

120103,Wilson,Dawes,M,87975,Sales Manager,AU,22JAN1953,01/01/1978             

120121,Irenie,Elvish,F,26600,Sales Rep. II,AU,02AUG1948,01/01/1978

120122,Christina,Ngan,F,27475,Sales Rep. II,AU,27JUL1958,07/01/1982

120123,Kimiko,Hotstone,F,26190,Sales Rep. I,AU,28SEP1968,10/01/1989

120124,Lucian,Daymond,M,26480,Sales Rep. I,AU,13MAY1963           

120125,Fong,Hofmeister,M,32040,Sales Rep. IV,AU,06DEC1958,03/01/1983

;;;;

Tom
Super User Tom
Super User

I suspect that your question is triggered by confusion between using formatted input and list mode input when writing your INPUT statement rather than the TRUNCOVER option of the INFILE statement. Take a look at this page:  SAS(R) 9.2 Language Reference: Concepts, Second Edition

The description of LIST INPUT style could use a little clarification:

  • The example INPUT statement has an unneeded $.  Because the variable has already been defined there is no need to include the $ in the INPUT statement.
  • The statement about blanks not representing a missing value only applies when you are using blank as your delimiter. Also look at the effect of modifiers such as & that are mentioned in the MODIFIED LIST INPUT style section.
  • They do not explain how the defined INFORMAT impacts the type data that can be read.  If you have defined an INFORMAT for your variables then you can read them with LIST INPUT style and the informat assigned to the variables in the list will automatically be read.
NoorulIyn
Calcite | Level 5

Thanks!Now I  understood clearly....

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1134 views
  • 9 likes
  • 4 in conversation