can length statements be used instead of truncover option in raw data sets
Are oranges better than apples?
I am new into SAS and can someone explain this both.Thanks
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.
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.....
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;
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?
v1 length 20 reading the same line
1 | 120102 | Tom | Zhou | M | 108255 | Sales Ma | AU |
---|---|---|---|---|---|---|---|
2 | 120103 | Wilson | Dawes | M | 87975 | Sales Ma | AU |
3 | 120121 | Irenie | Elvish | F | 26600 | Sales Re | AU |
4 | 120122 | Christin | Ngan | F | 27475 | Sales Re | AU |
5 | 120123 | Kimiko | Hotstone | F | 26190 | Sales Re | AU |
6 | 120124 | Lucian | Daymond | M | 26480 | Sales Re | AU |
7 | 120125 | Fong | Hofmeist | M | 32040 | Sales Re | AU |
8 | 120126 | Satyakam | Denny | M | 26780 | Sales Re | AU |
9 | 120127 | Sharryn | Clarkson | F | 28100 | Sales Re | AU |
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
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
;;;;
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:
Thanks!Now I understood clearly....
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 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.