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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.