DATA Step, Macro, Functions and more

Mask percenatage in data step

Accepted Solution Solved
Reply
Super Contributor
Posts: 266
Accepted Solution

Mask percenatage in data step

The below piece of code give me warning message.

I want to get rid of this warning, please suggest appropiate way to mask it.

 

%let k=XYZ.DT%DATE.;
data temp;
dsn="&k";
run;

 


Accepted Solutions
Solution
‎06-22-2017 03:47 AM
Super Contributor
Posts: 275

Re: Mask percenatage in data step

If % is part of text, %nrstr is needed to mask it. 

%let k=%nstr(XYZ.DT%DATE.);
data temp;
dsn="&k";
run;

 

View solution in original post


All Replies
PROC Star
Posts: 1,759

Re: Mask percenatage in data step

You are calling a macro called DATE.

Does it exist and what does it do and what is the error message?

Super Contributor
Posts: 266

Re: Mask percenatage in data step

My string has % in the text. I am not calling any macro.

PROC Star
Posts: 1,759

Re: Mask percenatage in data step

[ Edited ]

What's the message?

 

I bet it's  WARNING: Apparent invocation of macro DATE not resolved.  which is self explanatory really.

 

You need function %str() to use some characters in a macro value. Look it up.

 

See rules #1 and #2.

 

Super User
Posts: 7,762

Re: Mask percenatage in data step

I bet your log looks like this:

WARNING: Apparent invocation of macro DATE not resolved.
24         %let k=XYZ.DT%DATE.;
25         data temp;
26         dsn="&k";
WARNING: Apparent invocation of macro DATE not resolved.
27         run;

So what do you try to achieve by using the macro call(!) %date in the %let?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,498

Re: Mask percenatage in data step

It's difficult to remove both warnings.  The simplest way would be if you are allowed to change the value of your macro variable:

 

%let k='XYZ.DT%DATE.';

 

data temp;

dsn=&k;

run;

Super User
Super User
Posts: 7,942

Re: Mask percenatage in data step

I am going to assume from your code there that DSN means that XYZ is the library name and DT%DATE. is the dataset name, and that your keeping this information for some reason.  Personally I don't like data (dates in this case) in dataset names, as this complicates any further programming activity.  I also question why you need a macro variable, and dataset to hold this information.  Once you have created the libname referece XYZ then you will automatically have this information in sashelp.vtable, so you can simply your life by just doing:

libname xyz "...";

data temp;
  set sashelp.vtable (where=(libname="XYZ" and substr(name,1,2)="DT"));
run;

All macro language is is a way to create Base SAS code, it is not a replacement for Base SAS.

SAS Super FREQ
Posts: 289

Re: Mask percenatage in data step

%let k=%str(XYZ.DT%%DATE.);
data temp;
dsn=symget('k');
run;
proc print; run;

How about this?

Solution
‎06-22-2017 03:47 AM
Super Contributor
Posts: 275

Re: Mask percenatage in data step

If % is part of text, %nrstr is needed to mask it. 

%let k=%nstr(XYZ.DT%DATE.);
data temp;
dsn="&k";
run;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 180 views
  • 1 like
  • 7 in conversation