BookmarkSubscribeRSS Feed
Tonya_M
Calcite | Level 5

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;

3 REPLIES 3
Reeza
Super User

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.

Tonya_M
Calcite | Level 5

Thank you.

dishant
Calcite | Level 5

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

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
  • 3 replies
  • 778 views
  • 0 likes
  • 3 in conversation