DATA Step, Macro, Functions and more

Macro Drops Special Characters $.

Reply
New Contributor
Posts: 2

Macro Drops Special Characters $.

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;

Super User
Posts: 17,824

Re: Macro Drops Special Characters $.

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.

New Contributor
Posts: 2

Re: Macro Drops Special Characters $.

Thank you.

Contributor
Posts: 52

Re: Macro Drops Special Characters $.

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 &num;

  x1 = scan("&var.",&i.," ");

  x2 = scan("&value.",&i.," ");

  output;

  %End;

Run;

%mend;

%chk;

If any concern pls let me know

Ask a Question
Discussion stats
  • 3 replies
  • 209 views
  • 0 likes
  • 3 in conversation