BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Damon1
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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;

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

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;

 

ed_sas_member
Meteorite | Level 14

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;
Tom
Super User Tom
Super User

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;

 

Damon1
Obsidian | Level 7

very helpful, thank you 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

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.

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
  • 4 replies
  • 803 views
  • 2 likes
  • 4 in conversation