BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

Most likely there are equal signs in CONDITION and it is confusing to call to %TRIM().

Convert

    %trim(&condition)

to

    &condition

or to

  %trim(%superq(condition))

Peter_C
Rhodochrosite | Level 12

Pity a data step isn't an option. It protects so well against values like condition becoming confused with process.

forumsguy
Fluorite | Level 6

@Tom.. There is also one dot in my condition. How should I resolve it .. One of my conditions is

val_write_off ^=.

Since superq doesnot unmask it .. is there any other way.. I tried with other functions as well..However couldnt find out solution....

Peter_C
Rhodochrosite | Level 12

Use missing() function

Or

Use

Not column is null

Tom
Super User Tom
Super User

Why not just give up on that old %TRIM() macro and use %SYSFUNC() to call the TRIM() function.  That will not care about equal signs or periods.  If the value of CONDITION does not work for TRIM() function then it will also not work when used as code.

/* Build up new_condition and emit previous condition */

  %if &first %then %do;

     %if (&n > 1) %then %put new_condition is case when (&new_condition) ;

     %let new_condition=(%sysfunc(trim(&condition)));

  %end;

  %else %let new_condition=&new_condition or (%sysfunc(trim(&condition))) ;

forumsguy
Fluorite | Level 6

Tom...Got it corrected.. Guess I need to read on Syscall set ... it seems magical ....thanks a lot guys ..so many ways to solve the problem.... Awesome...

yashpande
Obsidian | Level 7

Hi ,

Even I have similar requirement. But its slightly modified its actually a group by based on what we call control table. It was earlier written in Base SAS but now they want to use it in SAS DI's SQL join code. Anyways,

What i want to have as output is

CASE Label1

WHEN A

THEN CASE LABEL2

WHEN D THEN CASE LABEL3

WHEN P THEN CASE CONDITION

WHEN (CODE1 OR CODE7) THEN FLAG="Y"

END

END

WHEN B

THEN CASE LABEL2

WHEN E THEN CASE LABEL3

WHEN Q THEN CASE CONDITION

WHEN (CODE2 OR CODE3) THEN FLAG="Y"

END

END

WHEN C

THEN CASE LABEL2

WHEN P THEN CASE LABEL3

WHEN  THEN CASE CONDITION

WHEN (CODE4) THEN FLAG="Y"

WHEN D

THEN CASE LABEL2

WHEN A THEN CASE LABEL3

WHEN R THEN CASE CONDITION

WHEN (CODE5 OR CODE6) THEN FLAG="Y"


I read your code and tried to modify it but somehow was unable to get the logic clear. I was stuck into this part.

%let first=%eval( &n=1 or %superq(prev_label1) ne %superq(label1)

I know I need nested loop in this only, but somehow was unable to figure it out since i am new to %syscall , open , close functions.


I also read this post.
https://communities.sas.com/thread/33885?start=0&tstart=0

My requirement is exactly same but in Macro language.

Need some guidance to resolve this

Tom
Super User Tom
Super User

Start a new thread for you new problem and link back to the other two threads.

Here is explanation of %let first=%eval( &n=1 or %superq(prev_label1) ne %superq(label1));

%let first= means that it is creating the macro variable FIRST.

%eval() will evaluate an arithmetic or logical expression and return the result as an integer (actually a string that looks like an integer).  In this case it is a logic expression so the result will be either 1 (true) or 0 (false).

&n=1 or %superq(prev_label1) ne %superq(label1) is the logical expression to evaluate.

&n=1 tests if this is the first observation read. N is a macro variable that is incremented by the code.

%superq(prev_label1) ne %superq(label1) Tests if LABEL1 macro variable is Not Equal to PREV_LABEL1

%superq() is a macro function to quote a macro variable's value. It takes the name of the macro variable as its argument.

So the result is the FIRST will 1 (or TRUE) when the current observation is first one for the group.  This mimics the FIRST. variables that you can use in DATA steps with BY statements.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 22 replies
  • 3363 views
  • 7 likes
  • 6 in conversation