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

Hello Experts,

 

I'm looking in my data LB_DOS for the rows with : "xxxxxx 31/12/2021". The macro variable &DatePubli2. has the value 31/12/2021, but my code doesn't work :

%put test &DatePubli2.;  /***test 31/12/2021***/


data DOSS3;
	set DOSS2;
	where LB_DOS like '%&DatePubli2.';
run;

Nor this :

 

data DOSS3;
	set DOSS2;
	if  prxmatch("m/&DatePubli2./oi",LB_DOS)> 0 
run;

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I don't have your data, and so can't test the code against your data. This works for me when I try to find records that have NAME end with ne from SASHELP.CLASS.

 

%let char=ne;

data a;
    set sashelp.class;
    where name like "%nrstr(%%)&char";
run;

So please try the %nrstr(%%) in your code to replace the single % sign before macro variable &datepubli2.

 

If that's not it either, then we need to see a portion of data set DOSS2 provided according to these instructions. Many people just ignore the instructions when I mention it. Please do not provide the data in any other manner, as that won't help, and we'll just ask you to follow the instructions again.

--
Paige Miller

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

We need to know the values of LB_DOS in data set DOSS2, and how this variable is formatted. If the variable is formatted as DDMMYY. or similar, you can't use LIKE because that works on character strings and your data variable is not a character string but a numeric. But that's a guess by me, so ...

 

Please show us typical values of LB_DOS in data set DOSS2, and also PROC CONTENTS output for this variable.

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
Thank you for the message. The values in the column are
LB_DOS (1 column, 3 rows for example)
Test on 31/12/2021
Test on 09/12/2021
Test on 01/12/2009
PaigeMiller
Diamond | Level 26

What does PROC CONTENTS show you about this variable in data set DOSS2?

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
Thank you for the message. The result of proc contents is : LB_DOS Char 50 $50. $50. LB_DOS
PaigeMiller
Diamond | Level 26

Use double quotes

 

	where LB_DOS like "%&DatePubli2";

Macro variables do not resolve inside of single quotes.

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
But unfortunately, I have 0 lines ..
PaigeMiller
Diamond | Level 26

Show us the log, include the code as it appears in the log. Copy the log as text and use the </> icon to include the log in your reply.

 

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

 

From now on, when code isn't working properly, show us the log so we can see the code in the log and any ERRORs, WARNINGs and NOTEs. Don't make us ask you to show us the log; do it automatically from now on when code isn't working.

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
28         data DOSS3;
29         	set DOSS2;
30         	where LB_DOS like "%&DatePubli2";
SYMBOLGEN:  Macro variable DATEPUBLI2 resolves to 31/12/2021
31         run;

NOTE: There were 0 observations read from the data set WORK.DOSS2.
      WHERE LB_DOS like '%&DatePubli2';
NOTE: The data set WORK.DOSS3 has 0 observations and 31 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
      
Tom
Super User Tom
Super User

Since the field is 50 bytes long and you are only using a wildcard at the start then perhaps there are invisible characters after the date string.  Such as TAB, CR, LF , Non-breaking space, null character. 

Does it help to add the % after the date?

 

Or perhaps the macro variable has leading spaces.  That can happen if you use the older CALL SYMPUT() function instead of the modern CALL SYMPUTX() function to create the macro variable.  It also also happen if you use PROC SQL INTO without the TRIMMED keyword.  The message generated by the SYMBOLGEN option will not show the leading spaces.  To see them use %PUT and add some visible characters before and after the macro variable reference.

%put |&DatePubli2|;

 

PaigeMiller
Diamond | Level 26

I don't have your data, and so can't test the code against your data. This works for me when I try to find records that have NAME end with ne from SASHELP.CLASS.

 

%let char=ne;

data a;
    set sashelp.class;
    where name like "%nrstr(%%)&char";
run;

So please try the %nrstr(%%) in your code to replace the single % sign before macro variable &datepubli2.

 

If that's not it either, then we need to see a portion of data set DOSS2 provided according to these instructions. Many people just ignore the instructions when I mention it. Please do not provide the data in any other manner, as that won't help, and we'll just ask you to follow the instructions again.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 10 replies
  • 1215 views
  • 1 like
  • 3 in conversation