Hi,
I'm having trouble getting the last few numeric variables of the attached data set to read.
i've had the best success with the following code:
DATA crayons;
INFILE 'C:\Users\dlobsien\Desktop\crayons.txt' dsd truncover;
INPUT number 1-3 color $ 4-31 @32 code $ RGB $ 40-55 pack 56-60 issued 61-65 retired 65-69;
With this, many of the "pack" and "issued" variables' data appear as missing, but all of the "retired" data seems to appear.
In the dataset, there is a value for each observation of the "pack" and "issued" variables, but only some for the "retired" variable. Each of the last three observations vary about their line position, and the "pack" var varies in length. the last two vars are years.
I've also tried putting "@57 pack", "pack :57-60 issued :61-64..." and other variations of this ad nauseam with varying degrees of success.
Any help would be greatly appreciated.
Hi @Damon1
Could you please try
DATA crayons;
INFILE 'C:\Users\dlobsien\Desktop\crayons.txt' truncover;
INPUT number 1-3 color $ 4-31 @32 code $ RGB $ 40-55 pack issued retired;
RUN;
Below works for me.
DATA crayons;
INFILE 'C:\Users\dlobsien\Desktop\crayons.txt' dlm=' ' truncover termstr=lf;
INPUT
number :best32.
+1 color $25.
code :$8.
+1 RGB $15.
+1 pack :best32.
issued :best32.
retired :best32.
;
issued=mdy(1,1,issued);
retired=mdy(1,1,retired);
format issued retired year4.;
run;
proc print;
run;
Hi @Damon1
Could you please try
DATA crayons;
INFILE 'C:\Users\dlobsien\Desktop\crayons.txt' truncover;
INPUT number 1-3 color $ 4-31 @32 code $ RGB $ 40-55 pack issued retired;
RUN;
Just read those field using list mode instead of column mode. You could actually read the RGB values into numbers if you want by telling SAS to treat the comma and parentheses as delimiter characters also.
data want ;
infile cards truncover dlm='( ,)' ;
input number 3. color $28. code $8. red green blue pack issued retired;
cards;
1 Almond #EFDECD (239, 222, 205) 120 1998
2 Antique Brass #CD9575 (205, 149, 117) 120 1998
3 Apricot #FDD9B5 (253, 217, 181) 24 1949
4 Aquamarine #78DBE2 (120, 219, 226) 64 1958
5 Asparagus #87A96B (135, 169, 107) 96 1993
6 Atomic Tangerine #FFA474 (255, 164, 116) 72 1972
7 Banana Mania #FAE7B5 (250, 231, 181) 120 1998
91 Raw Umber #714B23 (113, 75, 35) 64 1958 1990
92 Razzle Dazzle Rose #FF48D0 (255, 72, 208) 80 1990
;
Obs number color code red green blue pack issued retired 1 1 Almond #EFDECD 239 222 205 120 1998 . 2 2 Antique Brass #CD9575 205 149 117 120 1998 . 3 3 Apricot #FDD9B5 253 217 181 24 1949 . 4 4 Aquamarine #78DBE2 120 219 226 64 1958 . 5 5 Asparagus #87A96B 135 169 107 96 1993 . 6 6 Atomic Tangerine #FFA474 255 164 116 72 1972 . 7 7 Banana Mania #FAE7B5 250 231 181 120 1998 . 8 91 Raw Umber #714B23 113 75 35 64 1958 1990 9 92 Razzle Dazzle Rose #FF48D0 255 72 208 80 1990 .
You could also try reading all of them using list mode as it looks like the values with embedded spaces, color and RGB, have at least two spaces after them. So you can use the & modifier. You can either define the lengths of the character variables before the INPUT statement or add an inline informat specification with the colon modifier to give SAS something to use to guess how long you want the variables defined. The colon modifier will make it use list mode (read the next field) instead of formatted mode (reading a fixed number of bytes).
input number color &:$28. code :$8. RGB &:$14. pack issued retired;
very helpful, thank you 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.