Hello everyone! I am trying to build a data step dynamically, based on the value of the variable _N_. After some analysys and experimenting, it seems to me that I have to convert it to a macro before using it (I beg your trust on this part) but the problem is that the macro variable always resolves to the _N_ associated with the last observation of the ds in the set statement, if some_ds=SASHELP.CLASS then row_numbers resolves to 19. This is very odd to me, it's my understanding that the call symput is an execution phase statement, and I expect it to run every time the data step goes through the implicit loop. In other words, for the sashelp.class example, I would expect the call symput to run 19 times, the row_number variable being progressively overswritten with values from 1 to 19. Here some code for clarification: %macro my_macro; data final;
set some_ds;
call symput("row_number",_N_); output;
%do i=1 %to &some_value;
%if %sysevalf(&row_number=%substr(%scan(&my_peculiar_string,&i,"|"),2,2)) %then %do; my_field=some_calculation; %end; %else %do; my_field=some_other_calculations; %end; %end; %mend my_macro; The condition inside the %sysevalf is never met because the row_numbers resolves to 19 instead than 1,2,3,4,5,6...19. I found something online stating this: "The macro variable created by CALL SYMPUT can not be referenced inside the creating data step. But CALL EXECUTE, SYMGET and RESOLVE can be used to reference a macro variable with in the data step. " This is then followed up with "CALL EXECUTE statements get resolved first and then moved to the input stack while iterating the data step. If the argument is a SAS statement then it gets moved to the input stack immediately and starts to execute at the data step boundary" Maybe it's because I'm tired but I can't wrap my head around this, any bit of help would be really appreciated. Link to the article for reference: https://www.lexjansen.com/phuse/2009/po/PO15.pdf
... View more