How to concatenate string and numeric SAS Macro and use it in where statement

supercool djkazu

so I have a code like below

%let THIS_YEAR=2020;

%macro programall;
%do i = 2016 %to &THIS_YEAR;

%let num2  =%eval(&i-2000);
%let xxx= CAT("MP",&num2);

data t_&i.;
set table1;
where GROUP in ("&xxx");
run;

%end;

for example

when i=2016
    num2 = 2016-2000;
    num2 = 16;

and try to concatenate with "MP", so it should create xxx=MP16.

and try to use in where statement.

but it is causing error.

enter image description here

how can I create Macro Variable like "MP16"correctly, so I can use it in where clause?

Thanks

Tom

You cannot use functions in macro code, they are just treated as any other text to the macro processor. But there is no need to use a function to concatenate text in macro code. Just expand the macro variable where you want to use the text it contains.

%let xxx= MP&num2 ;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SAS How to name file with Macro Numeric and String concatenated?

From Dev

How to concatenate number to string in macro?

From Dev

SAS Macro, passing value as string to where clause

From Dev

SAS Macro, passing value as string to where clause

From Dev

SAS how to use a macro variable as a date

From Dev

How to Use sas macro to sampling multiple datasets

From Dev

How to i use %include to invoke a SAS macro

From Dev

How to use arithmetic operators with SAS macro variables

From Dev

Concatenate formatted string in macro

From Dev

Concatenate formatted string in macro

From Dev

Store result of numeric expression in SAS macro variable

From Dev

Concatenate string using the Excel Macro

From Dev

how to pass a string to a macro sas without special char

From Dev

How do I use a macro variable in R? (Similar to %LET in SAS)

From Dev

How to use table names that have spaces in a SAS macro?

From Dev

How to write conditional where statement in SAS Proc SQL?

From Dev

SAS : How to iterate a dataset elements within the proc sql WHERE statement?

From Dev

SAS: Selecting string list in macro

From Dev

How to concatenate numeric columns in R?

From Dev

macro variable is uninitialized after %let statement in sas

From Dev

SAS macro to resolve in proc sql into statement

From Dev

How to use comparison operator for numeric string in mysql?

From Dev

How to concatenate formatted values in SAS

From Dev

How do I properly concatenate this PHP echo statement with a string and a function?

From Dev

How to use/convert string defined in macro to integer?

From Dev

SAS : how to test if a variable is numeric

From Dev

concatenate string inside a select statement

From Dev

Can I concatenate numeric constant with string in C?

From Dev

Concatenate all non numeric strings in String array

Related Related

  1. 1

    SAS How to name file with Macro Numeric and String concatenated?

  2. 2

    How to concatenate number to string in macro?

  3. 3

    SAS Macro, passing value as string to where clause

  4. 4

    SAS Macro, passing value as string to where clause

  5. 5

    SAS how to use a macro variable as a date

  6. 6

    How to Use sas macro to sampling multiple datasets

  7. 7

    How to i use %include to invoke a SAS macro

  8. 8

    How to use arithmetic operators with SAS macro variables

  9. 9

    Concatenate formatted string in macro

  10. 10

    Concatenate formatted string in macro

  11. 11

    Store result of numeric expression in SAS macro variable

  12. 12

    Concatenate string using the Excel Macro

  13. 13

    how to pass a string to a macro sas without special char

  14. 14

    How do I use a macro variable in R? (Similar to %LET in SAS)

  15. 15

    How to use table names that have spaces in a SAS macro?

  16. 16

    How to write conditional where statement in SAS Proc SQL?

  17. 17

    SAS : How to iterate a dataset elements within the proc sql WHERE statement?

  18. 18

    SAS: Selecting string list in macro

  19. 19

    How to concatenate numeric columns in R?

  20. 20

    macro variable is uninitialized after %let statement in sas

  21. 21

    SAS macro to resolve in proc sql into statement

  22. 22

    How to use comparison operator for numeric string in mysql?

  23. 23

    How to concatenate formatted values in SAS

  24. 24

    How do I properly concatenate this PHP echo statement with a string and a function?

  25. 25

    How to use/convert string defined in macro to integer?

  26. 26

    SAS : how to test if a variable is numeric

  27. 27

    concatenate string inside a select statement

  28. 28

    Can I concatenate numeric constant with string in C?

  29. 29

    Concatenate all non numeric strings in String array

HotTag

Archive