I am attempting a do loop which scans 16 variables and 16 format values bouncing off of sashelp.vcolumns data. In my code I am creating a quality check that will notify me if conditions are not met including the format of the 16 variables. The problem is that the macro x2 populates as 10 or 40 instead of the intended string of "$10." "$40." Why does it drop the special characters and how can I correct that? do I have to concatenate?
code example:
data var_check; set sashelp.vcolumn (rename=(format=fmtt));
where MEMNAME = "&FILE" AND LIBNAME ="&LIB";
keep MEMNAME LIBNAME NAME TYPE FMTT LENGTH;
run;
%Let var = account_id product_id;
%let fmt = $10. $40. ;
%let num = 2;
Macro cat ;
%do i=1 to #
%let x1 = %scan(&var, &i);
%let x2 = %scan(&fmt, &i);
title "Wrong format for &x1"
select distinct name, fmtt
from var_check
where name = &x1
and fmtt <> "&x2";
quit;
%end; %end; %mend; %cat;
Its an automatic delimiter in the %scan function.
You're only looking for spaces so consider adding in a specific delimiter instead:
%let x2 = %scan(&fmt, &i, %str(" "));
%put &x2.;
There are other ways as well...look into the modifiers for %scan.
Thank you.
Hi,
Try this Piece of code.I didn't try on sas but hope it will help you to achieve your requirement.
%let var = acct_id product_id ;
%let value = $10 $40;
%let num = 2;
%macro chk;
data test;
%do i = 1 %to #
x1 = scan("&var.",&i.," ");
x2 = scan("&value.",&i.," ");
output;
%End;
Run;
%mend;
%chk;
If any concern pls let me know
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.