Help using Base SAS procedures

SAS Datastep

Reply
N/A
Posts: 0

SAS Datastep

Hello I need to obtain a single sas file which has all the periods Period 1 and Period2 ( period 2A + Period2B ).

Period 1 Period 2A Period 2B
Variable COLUMNS COLUMNS COLUMNS
Transaction ID 1 – 8 1 – 8 1 – 8
Date of Sale 9 – 18 9 – 18
Time of Sale 19 – 26 9 – 16
Laptop Model 27 – 32 19 – 24
Units Sold 33 – 35 25 – 27
Warranty 36 28

I've used the code -

libname sc 'c:\Sas';
data period1;
infile 'c:\Sas\period1_sales_data.dat.';
Input TransactionID $1-8
DateofSale $9-18
TimeofSale $19-26
LaptopModel $27-32
UnitsSold 33-35
Warranty 36 ;
proc print data = period1;
TITLE 'period1 sales';
run;


data period2A;
infile 'c:\Sas\period2_sales_data_A.dat.';
Input TransactionID $1-8
DateofSale $9-18
LapstopModel $19-24
UnitsSold 25-27
Warranty 28 ;
proc print data=period2A;
TITLE 'period2A sales';
run;


data period2B;
infile 'c:\Sas\period2_sales_data_B.dat';
Input TransactionID $1-8

TimeofSale $9-16;
Proc sort data = period2_sales_data_B;
By TransactionID;
proc print data=period2B;
TITLE 'period2B sales';
RUN;


Using the above code craetes two columns of the Laptop model , when one column ends at some point the data remaining is printed on the second column. I think that i need to change the oredr of the input variables in data setp.

Kindly guide,
markc
Regular Contributor
Posts: 165

Re: SAS Datastep

Posted in reply to deleted_user
Your code does nothing but read in data and print it (it also looks like that proc sort would fail). There is no creation of a file that holds both periods.

You need to take an hour or two and study the set and merge statements and see what each does. If you did that then you wouldn't have nearly half as many questions as you do.
Super Contributor
Super Contributor
Posts: 3,174

Re: SAS Datastep

The previous suggestions from your posts to read about SET/MERGE by BY as well as taking consideration with using SAS numeric variables for DATE and TIME type references has either been ignored or forgotten.

Individuals on these forums take the time to address the requests for help/guidance, only to find that a subsequent post continues with disregard to others' feedback.

Furthermore, as has been suggested, investing in time for self-checking of your program and the logs will go far to help one absorb useful habits when dealing with SAS program development and debugging.

So, given the latest post and your point about multiple variables representing laptops, as I see it you have two SAS variables, one named LapstopModel and another called LaptopModel -- maybe intentional but who knows. Also, your question is input data related and so you will be best suited to answer it, I believe, unless you are willing to generate SAS log diagnostics using commands, such as:

LIST;

putlog _infile_;

putlog _all_;

Again, to share only a non-working SAS program (as mentioned with the PROC SORT specification error), is not going to get you very far, in my experience. In the future, share all of your SAS code but do so with a captured/pasted SAS log output with it.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 269 views
  • 0 likes
  • 3 in conversation