08-21-2016 05:12 AM
I've a CSV file which has last one year (Aug'15 to Jul'16) data. Now my requirement is to import only last 3 months (Jul'16 , Jun'16 & May'16) records without hardcoding. File has a date variable which has values like 21JUN2016 , 20JUL2016 , 31DEC2015 alongside other variables.
Appreciate if someone guide me with the code.
08-21-2016 05:43 AM
08-21-2016 06:26 AM
How about this:
proc sql; create table want as select * from have where month(datevar) + 3 > ( select max(month(datevar) from have)); quit;
Hope this helps,
08-22-2016 05:11 AM
You'd better post some data to let us test code: proc sql; create table want as select * from sashelp.air having date ge intnx('month',max(date),-2) ; quit;
08-22-2016 10:16 AM
Thanks for the code.
Your code subsetting the data from master SAS dataset (sashelp.air). But my question is to creating a master datset with subset of records. i.e. I will need to create a SAS dataset by importing only selective records.
08-22-2016 10:34 PM
08-23-2016 03:51 PM - edited 08-23-2016 03:52 PM
I need to filter the records while importing not after importing
Good luck with that. If you are supposed to determine the last three months from the contents of the data file without reading it first then I suspect that you may have partially misunderstood the question.
Generically I would have looked at
1) read the data
2) determine the last date in the data set
3) then build a filter and subset the original data.
Or possibly the purpose of the question would be to get you to request clarification of the process.
08-23-2016 05:23 PM
I suspect that you may have partially misunderstood the question.
Interview questions are meant to test both understanding and technical ability so this is a good question according to that.
And yes, it's being misunderstood.
The solution is a single line of code (WHERE clause) in the data input step based on todays date and intnx function.