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
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;
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;
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.
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.).
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.