I can't take the time to thoroughly analyze this, but there is a prime suspect here:
%if %sysfunc (mod (&k.,4))=1%then %do;
This statement means that your interior macro executes for every 4th line only (k=1, k=5, k=9, k=13, etc.).
That logic may have been inserted for testing purposes, or perhaps to obtain a sample of the incoming data.
It is very hard to follow what your data is, the result and what you expected. It helps to post your data in the form of data step code so we can understand what you have or your result actually looked like. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... show how to creat datastep code from a SAS data set. You should paste the code in a forum code box opened with the {i} icon.
One possbile contributor is this line in your Proc SQL code:
From sashelp.vcolumn where libname='work' and memname='RAW' and substr (name,1,3)="ATM"
The values for LIbname and memname are both stored in UPPERCASE only. So you may not be getting the results you expect. Secondarily the NAME is in mixed case so if the variable is 'atm2' then substr (name,1,3)="ATM" won't match. Use substr(upcase (name,1,3))="ATM" to fix that.
I am not sure what you are attempting but the code as written only keeps 2 atm variables if that is what you a re asking about:
Set raw (keep=Createdate trackingnumber atm&i. Atm&j. );
If you post some data and what the expected result for that example data is then we may be able to provide more help. A description of what you are actually attempting wouldn't hurt.
I can't take the time to thoroughly analyze this, but there is a prime suspect here:
%if %sysfunc (mod (&k.,4))=1%then %do;
This statement means that your interior macro executes for every 4th line only (k=1, k=5, k=9, k=13, etc.).
That logic may have been inserted for testing purposes, or perhaps to obtain a sample of the incoming data.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.