DATA Step, Macro, Functions and more

Reading raw data set (The length of numeric variables is 3-8. )

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Reading raw data set (The length of numeric variables is 3-8. )

I've got an error message: The length of numeric variables is 3-8. I attached the raw data file (mydata). How can I load this data in SAS? Thanks.

The following is my data's layout information.

name type start width decimals

v1 C 1 1 0

v2 C 2 3 0

v3 C 5 3 0

v4 C 8 3 0

v5 C 11 3 0

v6 C 14 4 0

v7 C 18 4 0

v8 C 22 4 0

v9 C 26 4 0

v10 C 30 2 0

v11 C 32 2 0

v12 C 34 6 0

v13 C 40 1 0

U01 I 41 9 0

U02 I 50 9 0

U03 F 59 9 1

U04 I 68 9 0

Attachment

Accepted Solutions
Solution
‎05-10-2012 02:22 PM
Trusted Advisor
Posts: 1,301

Re: Reading raw data set (The length of numeric variables is 3-8. )

I would read this paper to better understand how SAS stores numeric data:

http://www.nesug.org/proceedings/nesug02/at/at002.pdf

data foo;

length _numeric_ 3; * I choose 3 instead of default of 8 because all my data is <= 8192 and I want to save space;

input (name type) ($) start width decimals;

cards;

v1 C 1 1 0

v2 C 2 3 0

v3 C 5 3 0

v4 C 8 3 0

v5 C 11 3 0

v6 C 14 4 0

v7 C 18 4 0

v8 C 22 4 0

v9 C 26 4 0

v10 C 30 2 0

v11 C 32 2 0

v12 C 34 6 0

v13 C 40 1 0

U01 I 41 9 0

U02 I 50 9 0

U03 F 59 9 1

U04 I 68 9 0

;

run;

View solution in original post


All Replies
Solution
‎05-10-2012 02:22 PM
Trusted Advisor
Posts: 1,301

Re: Reading raw data set (The length of numeric variables is 3-8. )

I would read this paper to better understand how SAS stores numeric data:

http://www.nesug.org/proceedings/nesug02/at/at002.pdf

data foo;

length _numeric_ 3; * I choose 3 instead of default of 8 because all my data is <= 8192 and I want to save space;

input (name type) ($) start width decimals;

cards;

v1 C 1 1 0

v2 C 2 3 0

v3 C 5 3 0

v4 C 8 3 0

v5 C 11 3 0

v6 C 14 4 0

v7 C 18 4 0

v8 C 22 4 0

v9 C 26 4 0

v10 C 30 2 0

v11 C 32 2 0

v12 C 34 6 0

v13 C 40 1 0

U01 I 41 9 0

U02 I 50 9 0

U03 F 59 9 1

U04 I 68 9 0

;

run;

Super User
Posts: 5,513

Re: Reading raw data set (The length of numeric variables is 3-8. )

To continue the learning experience, try running FriedEgg's program and then run a PROC CONTENTS on the results.

Then swap the order of the LENGTH and INPUT statements, and repeat the process.  Notice how the length of  your numeric variables changes.

Good luck.

Contributor
Posts: 40

Re: Reading raw data set (The length of numeric variables is 3-8. )

Thanks all. The attached "mydata" is the actual data file. Sorry for the confusion. Anyway, by taking Astounding's advice of INPUT statements, I could first read the U1-U4 variables as character, and then convert them into numeric using the INPUT statements: U1new = input(U1, 9.).

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1303 views
  • 0 likes
  • 3 in conversation