Hi,
I have to implement a series of flags (I would also be happy using counters instead) (via a macro) to flag (count) unique occurrences of variables. The data must be sorted by variables 'a', 'b' and 'c' but I only want to increment the counter when a new instance of 'c' occurs within each 'a'. Is that possible? (specifically, my problem is that the 'c' flag = 1 every time I encounter a new 'b', which I don't want).
I suppose I could create a new sort variable that concatenates 'a' and 'b', but I was hoping there was a more elegant solution?
data &dataset.;
set &dataset.;
by a b &c. ;
if last.&c. then &c._flag = 1; else &c._flag = 0;
run;
First, get a non macro solution working.
Second, post some example data please that illustrates your issue.
It's sometimes hard to follow the logic in words, and sometimes the correct terms aren't used but having the data makes that easier to determine.
You should be able to use IF first.C directly as far as I can tell, so not sure what B has to do with it, but an example will clarify that.
If you're uncertain you can also review the examples in the BY group processing in the documentation.
First, get a non macro solution working.
Second, post some example data please that illustrates your issue.
It's sometimes hard to follow the logic in words, and sometimes the correct terms aren't used but having the data makes that easier to determine.
You should be able to use IF first.C directly as far as I can tell, so not sure what B has to do with it, but an example will clarify that.
If you're uncertain you can also review the examples in the BY group processing in the documentation.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.