05-05-2014 11:09 AM
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?
data var_check; set sashelp.vcolumn (rename=(format=fmtt));
where MEMNAME = "&FILE" AND LIBNAME ="&LIB";
keep MEMNAME LIBNAME NAME TYPE FMTT LENGTH;
%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
where name = &x1
and fmtt <> "&x2";
%end; %end; %mend; %cat;
05-05-2014 11:20 AM
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(" "));
There are other ways as well...look into the modifiers for %scan.
05-07-2014 02:57 AM
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;
%do i = 1 %to #
x1 = scan("&var.",&i.," ");
x2 = scan("&value.",&i.," ");
If any concern pls let me know