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

Dear all,

I try to keep only the first 11 character from string with carriage return.

ex: 

"In progress. # 1 DCF[ CLOSED ] 02/03/2017 15:46Mr A. ADJE wrote null.and proposed value 999,999,999. 30/06/2017 11:10Mme 
M. CANEAU wrote ok.and proposed value null. # 1 Notification. Change performed by Mme M. CANEAU on 30/06/2017 11:10 :ok-new 
value: null"

 

 Please find my sentence in my macro:

%let fileDel2=%unquote(%sysfunc(getvarc(&tabid2,%sysfunc(varnum(&tabid2,&nomvar2))))); 
%put &fileDel2; 
%let nou=%substr(&fileDel2,1,11);
%put &nou;

 

The log displays:
In progress. # 1 DCF[ CLOSED ] 02/03/2017 15:46Mr A. ADJE wrote null.and proposed value 999,999,999. 30/06/2017 11:10Mme 
M. CANEAU wrote ok.and proposed value null. # 1 Notification. Change performed by Mme M. CANEAU on 30/06/2017 11:10 : ok - new 
value: null
ERROR: Macro function %SUBSTR has too many arguments.
ERROR: The macro KEEPMONITORTAB will stop executing.

 

If i perform directly on table without macro, it works.

What can I do for that works also throught macro?

 

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You can probably (can't get it right now) get away with this:

 

%let nou = %unquote( %substr(%superq(fileDel2), 1, 11) ) ;

 

Most likely, the problems occur because of the commas within the value of &fileDel2.  %SUBSTR interprets them as marking the end of one parameter and the beginning of the next.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Simple answer: don't do it. Macro language is for the creation of dynamic code, not for manipulating data.

An abomination like

%let fileDel2=%unquote(%sysfunc(getvarc(&tabid2,%sysfunc(varnum(&tabid2,&nomvar2)))));

is the consequence of trying to abuse the macro processor.

Astounding
PROC Star

You can probably (can't get it right now) get away with this:

 

%let nou = %unquote( %substr(%superq(fileDel2), 1, 11) ) ;

 

Most likely, the problems occur because of the commas within the value of &fileDel2.  %SUBSTR interprets them as marking the end of one parameter and the beginning of the next.

PSIOT
SAS Employee

Thank  you that works

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 2419 views
  • 0 likes
  • 3 in conversation