DATA Step, Macro, Functions and more

macro variable quoting

Reply
Contributor
Posts: 66

macro variable quoting

I have a macro variable called dsn_n and it contains a list of worksheets I would like to access via a libname statement.  For example, the contents of the macro variable could be: 'LMUD_and_Plumas-Sierra$'n 'Lassen MUD$'n 'PGE MID$'n 'SDG&E$'n

I would like to loop through the contents of the macro variable dsn_n and grab data in the worksheet such as:

%macro get_data ;

%let j = 1 ;

%do %until (%scan(&dsn_n,&j) = ) ;

data xyz ;

set mylib.&temp_dsn ;

run ;

%let j = %eval(&j+1) ;

/*append xyz to file perm */

%end ;

%mend get_data ;

I seem to run against issues with macro variable quoting and need some help so that I can loop the macro variable dsn_n and grab the data.  Macro variable quoting seems to be confounding me and I have spent some goggling this topic and I am still not sure how to proceed.

Super User
Posts: 11,343

Re: macro variable quoting

Posted in reply to asishgautam

You have a couple issue.

You say the variable containing the names is dsn_n but don't reference it, I would expect to see &dsn_n. Or do you mean that you have a series of macro variables dsn_1, dsn_2, ....?

If you do have one variable that you need to pull the first, second, third etc from then I would expect to see a

a variable assignment as follows unless you meant but did not include something like:

%let temp_dsn = %qscan(&dsn_n,&j,' ');

Because your string contains '  characters you probably need to use %qscan

By default %scan and %qscan use $ as one of the delimiters so you haven't been getting the breaks where you expect. Specify to only use the blank as the delimiter.

And mayby instead of trying to use %until you can get the actual count of variables and use an explicit loop:

%do j = 1 %to %sysfunc(countw(&string,' '));

%let temp_dsn = %qscan(&dsn_n,&j,' ');

<your code here>

%end;

Also to help with questions like this in the futue, run your code with options MPRINT to show us the actual generated code. Include the errors, at least for a few iterations of the loop.

Contributor
Posts: 66

Re: macro variable quoting

Here is the code below:

%put &dsn ;

%macro test_m ;

    %let j = 1 ;

    %do %until (%qscan(&dsn,&j) eq ) ;

        %let t_n = %qscan(&dsn,&j) ;

        %put &t_n ;

        data xyz ;

            set zip_d.&t_n ;

        run ;

        proc append base = master data = xyz ;

        run ;

        %let j = %eval(&j+1) ;

    %end ;

%mend test_m ;

%test_m

the log shows:

93   %put &dsn ;

'LMUD_and_Plumas-Sierra$'n 'Lassen MUD$'n 'PGE MID$'n 'SDG&E$'n 'Truckee-Donner_PUD$'n

'Aha_Macav$'n 'Alameda$'n 'Anaheim$'n 'Anza$'n 'Azusa$'n 'Banning$'n 'Biggs$'n 'Burbank$'n

'Cerritos$'n 'City_of_Corona$'n 'Colton$'n 'County_city_of_SF$'n 'Glendale$'n 'Gridley$'n

'Healdsburg$'n 'Hercules$'n 'IID$'n 'Industry$'n 'Kirkwood$'n 'Liberty$'n 'Lodi$'n 'Lompoc$'n

'Los_Angeles$'n 'Merced$'n 'Modesto$'n 'Moreno_Valley$'n 'Morongo$'n 'Needles$'n

'PCORP_and_Suprise_Valley$'n 'PGE$'n 'PacifiCorp$'n 'Palo_Alto$'n 'Pasadena$'n 'Pittsburg$'n

'Plumas$'n 'Port_of_Oakland$'n 'Port_of_Stockton$'n 'Rancho_Cucamonga$'n 'Redding$'n

'Riverside$'n 'Roseville_Electric$'n 'SCE$'n 'SMUD$'n 'Shasta$'n 'Shelter_Cove$'n

'Silicon_Valley$'n 'Surprise_Valley$'n 'TID$'n 'Trinity$'n 'Ukiah$'n 'Valley$'n 'Vernon$'n

'Victorville$'n

94

95   %macro test_m ;

96       %let j = 1 ;

97       %do %until (%qscan(&dsn,&j) eq ) ;

98           %let t_n = %qscan(&dsn,&j) ;

99           %put &t_n ;

100          data xyz ;

101              set zip_d.&t_n ;

102          run ;

103          proc append base = master data = xyz ;

104          run ;

105          %let j = %eval(&j+1) ;

106      %end ;

107  %mend test_m ;

108

109  %test_m

'LMUD_and_Plumas

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'LMUD_and_Plumas ;

ERROR: File WORK.LMUD_AND_PLUMAS.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'LMUD_and_Plumas

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

Sierra

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.Sierra ;

ERROR: File ZIP_D.Sierra.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.03 seconds

      cpu time            0.03 seconds

'Lassen

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Lassen ;

ERROR: File WORK.LASSEN.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Lassen

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MUD

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.MUD ;

ERROR: File ZIP_D.MUD.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'PGE

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'PGE ;

ERROR: File WORK.PGE.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'PGE

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MID

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.MID ;

ERROR: File ZIP_D.MID.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'SDG

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'SDG ;

ERROR: File WORK.SDG.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'SDG

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

E

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.E ;

ERROR: File ZIP_D.E.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Truckee

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Truckee ;

ERROR: File WORK.TRUCKEE.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Truckee

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.03 seconds

      cpu time            0.03 seconds

Donner_PUD

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.Donner_PUD ;

ERROR: File ZIP_D.Donner_PUD.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Aha_Macav

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Aha_Macav ;

ERROR: File WORK.AHA_MACAV.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Aha_Macav

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Alameda

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Alameda ;

ERROR: File WORK.ALAMEDA.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Alameda

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.00 seconds

'Anaheim

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Anaheim ;

ERROR: File WORK.ANAHEIM.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Anaheim

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Anza

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Anza ;

ERROR: File WORK.ANZA.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Anza

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.03 seconds

      cpu time            0.03 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Azusa

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Azusa ;

ERROR: File WORK.AZUSA.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Azusa

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Banning

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Banning ;

ERROR: File WORK.BANNING.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'Banning

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.03 seconds

      cpu time            0.03 seconds

'n

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'n ;

ERROR: File WORK.N.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

MPRINT(TEST_M):   proc append base = master data = xyz ;

MPRINT(TEST_M):   run ;

NOTE: Line generated by the macro variable "T_N".

1     zip_d.'n

      ------

      22

      201

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, END,

              INDSNAME, KEY, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

NOTE: Appending WORK.XYZ to WORK.MASTER.

NOTE: There were 0 observations read from the data set WORK.XYZ.

NOTE: 0 observations added.

NOTE: The data set WORK.MASTER has 0 observations and 0 variables.

NOTE: PROCEDURE APPEND used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

'Biggs

MPRINT(TEST_M):   data xyz ;

MPRINT(TEST_M):   set zip_d.'Biggs ;

ERROR: File WORK.BIGGS.DATA does not exist.

MPRINT(TEST_M):   run ;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.XYZ may be incomplete.  When this step was stopped there were 0

         observations and 0 variables.

WARNING: Data set WORK.XYZ was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

Valued Guide
Posts: 2,177

Re: macro variable quoting

Posted in reply to asishgautam

I was surprised to see that you have no clear boundary for the %QSCAN() function.

That might be resolved by replacing 'n ' with 'n#' and using a # delimiter for qscan, like

       %let t_n = %qscan(&dsn,&j,#) ;

Not having SAS/ACCESS TO PC FILES here, I'm unable to be sure that that works

       

personally I tell suppliers to create a RANGE NAME for any ranges they want me to read (indicating the kind of range names I like which - coincide with SAS table name rules - and should be defined in upper case).

Super User
Super User
Posts: 7,077

Re: macro variable quoting

Posted in reply to asishgautam

You need to use the Q modifier on the SCAN() and COUNTW() functions.

Try running these examples using data step and macro logic.

data _null_ ;

  list='''LMUD_and_Plumas-Sierra$''n ''Lassen MUD$''n ''PGE MID$''n ''SDG&E$''n';

  do i=1 to countw(list,' ','q') ;

   word = scan(list,i,' ','q');

   put i= word=;

  end;

run;

%macro test ;

%let list='LMUD_and_Plumas-Sierra$'n 'Lassen MUD$'n 'PGE MID$'n 'SDG&E$'n;

%do i=1 %to %sysfunc(countw(&list,%str( ),q)) ;

   %let word=%scan(&list,&i,%str( ),q);

   %put i=&i word=&word;

%end;

%mend;

%test;

Both should yield the same output:

i=1 word='LMUD_and_Plumas-Sierra$'n

i=2 word='Lassen MUD$'n

i=3 word='PGE MID$'n

i=4 word='SDG&E$'n


Ask a Question
Discussion stats
  • 4 replies
  • 937 views
  • 0 likes
  • 4 in conversation