BookmarkSubscribeRSS Feed
Macro
Obsidian | Level 7

Hi,

The data A is in the format of NegParen16 (comma delimited, negative number  in parentheses format),  Y is a macro variable with value 6,243,423 get from an observation of X1.

The following procedure

proc univariate data=A noprint;

      var X1;

      output out=B mean=X1;

      where X1 <= &Y;

    run;

Has error:

Syntax error while parsing where clause.

Basically it has X1 <= 6,243,423. It cannot handle these commas.

Q: How do fix it without changing the data format of data A?









4 REPLIES 4
Reeza
Super User

Remove the comma's from the macro variable. The where will check the underlying value, the format is only for display.

Macro
Obsidian | Level 7

Indeed, I used the follwoing to generate 100 macro variables my_xx since data A has 100 variables:

proc sql noprint;
  select name into :dname separated by ','
         from dictionary.columns
         where libname="WORK" and memname="A";

  select compress(":"||"my_"||name) into: mdname separated by ','
         from DICTIONARY.COLUMNS
         WHERE LIBNAME="WORK" AND MEMNAME="A";

* How do you modify the following so that my_XX macro variables do not have commas and parentheses?;


  select &dname into &mdname
         from A;
quit;

* &mdname (list of variables that play the role of Y above) is the one has comma and parentheses and coused problem;

Reeza
Super User

What are you trying to do?

I'm lost Smiley Sad

Astounding
PROC Star

The COMPRESS function can remove more than blanks.  You just have to tell it what to remove, or what to keep.  You would do this by adding between ||name and the closing parenthesis.  Some examples:

compress(var)  removes blanks

compress(var, '( ),')  removes parentheses, blanks (because there is a blank between the quoted parentheses), and commas.

compress(var,,'kd')  keeps digits only and discards the rest of the characters

Your problem may be more complex than this because you may need to replace parentheses with a negative sign, rather than just removing them.

Are we getting closer?  Would it make sense to go back to Reeza's original suggestion and change the earlier code that creates the macro variables instead of fixing the problem later?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1087 views
  • 0 likes
  • 3 in conversation