BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gil_
Quartz | Level 8
I have a table named Raw
That looks like this

Create date Tracking number AtM1
01/25/17. 1ZT248. Bagbar:"RS7779704"

Atm2. Atm3
ATMBAR:"IN6618220125. Bagbar:"RS7779703"

ATM4. ATM5
ATMBAR: "IN540322025" BAGBAR:"RS7779167"
txt me? 352-440-3968

ATM8
ATMBAR:"IN1933220125"

these are in one row horizontal the macro looks like this

Proc sql no print;
Create table numatms as select
Distinct name,input (substr (name,4,4),8.0) as num
From sashelp.vcolumn where libname='work' and memname='RAW' and substr (name,1,3)="ATM"
ORDER BY 2;
QUIT;
PROC SQL NO print ; select max (num) into :nuatms from numatms;quit;
%put &numatms;
Proc sort data =raws; by Createdate trackingnumber; run;
Data outputs_results;run;

%Marco c (i);
%let j=%sysfunc (sum (&i,1));
%put &j.;

Data ext ( rename=(atm&i=atm_bag atm&j=atm_bar));
Format Createdate date9. Trackingnumber $18.;
Length atmi. Atmj. $256;
Set raw (keep=Createdate trackingnumber atm&i. Atm&j. );
Run;

Data outputs_results;
Set outputs_results ext;
Label atm_bag ="ATM" ATM_BAR="ATM";
IF CREATEDATE =. then delete;
Run;
%mend;
%marco r;
%do k=1 %to &numatms;
%if %sysfunc (mod (&k.,4))=1%then %do;
%c (&k);
%end;
%end;
%mend;
%r



Output
Is only 2 out of 4
Barcode RS7779704
BARCODE RS7779167


I don't know why it excludes the other two ... there is no spaces or character

Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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. 

View solution in original post

6 REPLIES 6
Gil_
Quartz | Level 8
 
ballardw
Super User

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.

Gil_
Quartz | Level 8
I tried the uppercase same results the raw data looks like this
Date tracking ATM1 ATM2 ATM3 ATM4 ATM5 ATM6
The out put I would like to see
Date tracking ATM1 ATM2
Date tracking ATM3 ATM4
Date tracking ATM5 ATM6
Astounding
PROC Star

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. 

Gil_
Quartz | Level 8
I tried the uppercase same results the raw data looks like this
Date tracking ATM1 ATM2 ATM3 ATM4 ATM5 ATM6
The out put I would like to see
Date tracking ATM1 ATM2
Date tracking ATM3 ATM4
Date tracking ATM5 ATM6


Once I change the number%if %sysfunc (mod (&k.,4))=1%then %do; to 7 the col would overlap
it shows
ATM ATM
Gil_
Quartz | Level 8
Thsnks astounding I change the number to 7 and it brought in the 2 thst was missing. I will run a full set of data to see if it fixes it

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1121 views
  • 1 like
  • 3 in conversation