BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jayakumarmm
Quartz | Level 8

 

I need to do a wordcount based on comma delimiter and pass the delimiter parameters into macro.

Currently it is retreving both the arguments like  FILE1,FILE2 & DATA1,DATA2

 

 

 

%let Filename_1 = FILE1,FILE2;
%let SAS_DATASET = DATA1,DATA2;

%macro file_process;
%let word_cnt = %sysfunc(countW(&Filename_1,','));
%do  i = 1 %to &word_cnt;
%let file_name=%scan('&Filename_1',&i,',');
%let dataset=%scan('&SAS_DATASET',&i,',');
%end
%mend file_process;

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Hi

 

Since the SAS Macro Language is text based you do not need to use quotes. Since some of your text contains characters which have a meaning in the macro language (comma separating arguments in functions) you need to use quoting functions.

 

To understand quoting functions, I recommend to read the following blog

http://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/

 

 

Below is the changed code:

 

%let Filename_1 = FILE1, FILE2;
%let SAS_DATASET = DATA1, DATA2;

%macro file_process;
  %let word_cnt = %sysfunc(countW(%bquote(&Filename_1), %str(,)));
  %put NOTE: &=word_cnt;

  %do i=1 %to &word_cnt;
    %let file_name = %scan(%bquote(&Filename_1), &i, %str(,));
    %let dataset = %scan(%bquote(&SAS_DATASET), &i, %str(,));
    %put NOTE: &=i &=file_name &=dataset;
  %end;
%mend file_process;

%file_process

Bruno

View solution in original post

1 REPLY 1
BrunoMueller
SAS Super FREQ

Hi

 

Since the SAS Macro Language is text based you do not need to use quotes. Since some of your text contains characters which have a meaning in the macro language (comma separating arguments in functions) you need to use quoting functions.

 

To understand quoting functions, I recommend to read the following blog

http://blogs.sas.com/content/sgf/2014/08/15/macro-quoting-made-easy/

 

 

Below is the changed code:

 

%let Filename_1 = FILE1, FILE2;
%let SAS_DATASET = DATA1, DATA2;

%macro file_process;
  %let word_cnt = %sysfunc(countW(%bquote(&Filename_1), %str(,)));
  %put NOTE: &=word_cnt;

  %do i=1 %to &word_cnt;
    %let file_name = %scan(%bquote(&Filename_1), &i, %str(,));
    %let dataset = %scan(%bquote(&SAS_DATASET), &i, %str(,));
    %put NOTE: &=i &=file_name &=dataset;
  %end;
%mend file_process;

%file_process

Bruno

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
  • 1 reply
  • 2523 views
  • 0 likes
  • 2 in conversation