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

10. The raw data file Mixed_Recs.txt contains two types of records. Records with a 1 in Column 16
contain sales records with Date (in mmddyy10. form) starting in Column 1 and Amount in Columns
11–15 (in standard numeric form). Records with a 2 in Column 16 are inventory records and they
contain two values, a part number (character, 5 bytes) starting in column 1 and a quantity. These two
values are separated by a space. A listing of this file is shown below:
10/21/2005 1001
11/15/2005 2001
A13688 250 2
B11112 300 2
01/03/2005 50001
A88778 19 2
Write a DATA step to read this file and create two SAS data sets, one called Sales and the other
Inventory. The two data sets should look like this:

1 ACCEPTED SOLUTION

Accepted Solutions
Dennis_K
Obsidian | Level 7

data sales(keep=saleDate Amount) inventory(keep=partno Quantity);
 infile '/home/wckwone/SASbyExample/mixed_recs.txt' truncover;
 input @16 type 1. @;

 if type=1 then do;
  input @1 saleDate mmddyy10. Amount 11-15;
  output sales;
 end;

 else do;
  input partno $1-6 Quantity 8-11;
  output Inventory;
 end;
run;

View solution in original post

5 REPLIES 5
Dennis_K
Obsidian | Level 7
my code is as follows:

data sales inventory;
infile '/home/wckwone/SASbyExample/mixed_recs.txt' truncover;
input @16 type 1. @;

if type=1 then do;
keep saleDate Amount;
input @1 saleDate mmddyy10. Amount 11-15;
output sales;


end;

else do;
keep partno Quantity ;

output Inventory;

end;

drop type;
run;
Kurt_Bremser
Super User

KEEP is a declarative statement that affects all output datasets and is dealt with at compile time. So it is not executed, meaning it cannot be used conditionally.

Use KEEP= dataset options in the DATA statement instead.

Dennis_K
Obsidian | Level 7

data sales(keep=saleDate Amount) inventory(keep=partno Quantity);
 infile '/home/wckwone/SASbyExample/mixed_recs.txt' truncover;
 input @16 type 1. @;

 if type=1 then do;
  input @1 saleDate mmddyy10. Amount 11-15;
  output sales;
 end;

 else do;
  input partno $1-6 Quantity 8-11;
  output Inventory;
 end;
run;

Kurt_Bremser
Super User

So what is your question now?

If you receive messages in the log that puzzle you, or the result does not match your expectations, post the complete log by copy/pasting it into a window opened with this button:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Similarly, post a few lines of your input data, using the same method.

 

Dennis_K
Obsidian | Level 7

@Kurt_Bremser Initially, I have problems dropping the unnecessary columns. Your Suggestion have solve the issue.

Thanks a lot.

 

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!
How to Concatenate Values

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.

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
  • 5 replies
  • 683 views
  • 1 like
  • 2 in conversation