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.
can you post some sample have dataset and what columns you want that would be helpful to give better solution. Thanks
@Babloo Shouldnt you complete interview questions on your own? It's not a fair representation of your skill set otherwise.
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,
- Jan.
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;
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.
@Babloo wrote:
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.
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.