03-21-2012 05:31 AM
My datset is as follows
obs f1 f2 f3 f4
1 1 2 3 4
2 3 4 5 6
3 7 6 6 8
with respect to condition like if obs =3 and f4=8 i need to fetch the value 8.
how can i achieve this?
03-21-2012 06:58 AM
I need to fetch one value from the dataset with respect to column name obs and f4.
So that when i run the code i only get the value 8 as i mentioned.
03-22-2012 04:23 AM
Your code is not as efficient as mine.
My code used Directly Access Method. However yours is Sequential Access Method.
If the dataset were very large. My code is better.
08-13-2013 11:49 AM
I am totally new in SAS programming. I need to calculate last 6 months of current month. and it should be in yyyymm format. (eg: 201308) I was able to get the current date. but cannot find a solution to update the table with last 6 months.
this is how I appraoched. Please help.
Format Cur_month YYMMN.
/*may be something like this is what I need*/
/*Mon1 = Cur_month-1;*/
/*Mon2 = Cur_month-2;*/
/*I did not get the right value in these fields. I got something like 19582, 19582, 19580*/
I tried to format it after calculating which again gave the value 201308. but it should be 201307, 201306, 201305
08-13-2013 01:05 PM
It would have been better to create a new thread as your question has no apparent bearing on the this thread.
The function you are looking for to create shifts of a data is INTNX.
I think you want Mon1 = INTNX("month",Cur_month, -1) ; The is an alignment parametere that can follow the -1 but you don't say whether the Mon1 should have a date represeting the begining, end, middle of the month or align with the same day of the month as Cur_month.
Your problem stems from subracting one day from the date value. If you used an MMDDYY format you would have seen your MonX variables decreasing by one day.
08-15-2013 05:00 AM
Thanks for the help.
I got what I wanted to do. I used Intnx and got it working
mon1 = intnx('month', date(), -1);
mon2 = intnx('month', date(), -1);
format mon1, mon2,mon3.. yymmn6. ;
Thanks everybody for the help. I am totally new to this field and trying to learn as far as I can..
08-13-2013 01:11 PM
If we are into code optimization, then you may want to review the position of the keep statement so that you don't "waste" memory allocation for a data vector of 5 variables when you only need one
Eleenrose, the issue is that all dates formats are held by sas as the number of days since 1960jan01. As such, when you substrat a day to your variable, even though its format is yymmn, it actually substracts 1 day from the date numeric value and then converts it back as a yymmn format so if a given date value was on the 16th of the month, you would need to substract 16 to eventually see the formatted substraction result change month after formating.
Intnx is the primary sas function to allow you to go around this issue.
mon1 = intnx('month', cur_month, -1);
Depending on your desired result, you may want to check the documentation for the 4rth parameter. By default from the above, the result will be the equivalent of the first day of the previous month and not the "same day" of the previous month.
Need further help from the community? Please ask a new question.