01-21-2015 07:51 PM
I am new to DI and I am not sure if this has been answered elsewhere, but does anyone know how to create a flag or a counter for the first time a value appears for a dataset?
In SAS BASE code, I use:
if first.variable then count = 1;
Any help on this would be extremely helpful. If anything doesn't make sense let me know.
Thanks in advance.
01-21-2015 08:52 PM
I believe this is the right approach.
first sort the dataset on the variables in which you want the data to sort and then use first.var to flag the record. Please let me know if this has not worked for you or provide a sample data .
01-21-2015 09:34 PM
Thanks for the quick response. The approach I mentioned works in EG but I need a DI method that does the same thing.
I have searched online and tried to use ROWNUMBER or ROWCOUNT but DI informs me that it cannot find those functions.
01-21-2015 11:08 PM
I was able to use monotonic!
I ended up using monotonic to create a row number and then using min() to get the lowest row number for my variable. Followed by applying a boolean value where 1 was the min row number and 0 was any succeeding row.
Thank you for your help!!
01-21-2015 11:28 PM
Thanks for the warning, I'll use it for testing and validation purposes but keep it out of my production jobs.
In the meantime, I'll keep hunting for a supported method :smileygrin:.
01-22-2015 06:04 PM
You can't use monotonic() interchangeable with first. processing of the data step. It' more like the _n_ variable.
But if it fits your current need, great.
To be able to use first. processing in DIS, you need to use User Written code, there is no "pure" data step transformation available.
About montonic() being unsupported, one funny thing is that is now being used within the Data Validation transformation. Wonder if SAS is supporting that...