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


Hi,

I am creating a macro for create table in teradata and i woudl like to call that macro for each table. So i have wrote the below mentioned code but i am getting a typical warning and the table is not created as below

Code:

%let ini= VK;

%let fcode=ab123;

%let work=wt;

%let brand2 = Very;

%let SEASON2=AW14;

%macro filecheck (DB=, Tablename=, sql_code=, indx=);

proc sql;

connect to teradata (user=&user. password=&password. mode=teradata);

OPTIONS COMPRESS=YES;

EXECUTE    (ct &tablename. &sql_code. &indx.) by teradata;

%mend;

  %filecheck_create
(DB=*****, Tablename=
%put(%trim(&ini._&Fcode._brow_&brand2._&season2.)_&work.),

sql_code=(aba, abc), indx= primary index (abc)) by teradata;

WARNING: The quoted string currently being processed has become more than 262 characters long.  You might have unbalanced quotation marks.

Above code resolving the table name but it is not creating the table and generating the warning. Can some one help what is the solution for the same to define table in the same pattern.

Regards,

Venkat P

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

I suspect that the this is the problem:

%put(%trim(&ini._&Fcode._brow_&brand2._&season2.)_&work.)

Not sure why you need the %put to start with.  Also the %trim is great, however your not trimming the individual elements:

Use options mlogic mprint symblogen;

You will see that &ini for instance will resolve as the text, plus some spaces (up to minimum length 8 I believe)so your output may look like:

ini=xyxy, bran2=tytyty

xyxy    _brow_tytyty   ...

Try to trim each bit:

%trim(&ini)_%trim(&fcode)_brow_%trim(&brand2)...


AS a final thought, you might want to consider using catx function e.g:

%sysfunc(catx("_",&ini.,&fcode.,"_brow_",&brand2....)

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

I suspect that the this is the problem:

%put(%trim(&ini._&Fcode._brow_&brand2._&season2.)_&work.)

Not sure why you need the %put to start with.  Also the %trim is great, however your not trimming the individual elements:

Use options mlogic mprint symblogen;

You will see that &ini for instance will resolve as the text, plus some spaces (up to minimum length 8 I believe)so your output may look like:

ini=xyxy, bran2=tytyty

xyxy    _brow_tytyty   ...

Try to trim each bit:

%trim(&ini)_%trim(&fcode)_brow_%trim(&brand2)...


AS a final thought, you might want to consider using catx function e.g:

%sysfunc(catx("_",&ini.,&fcode.,"_brow_",&brand2....)

venkata_peddisetty
Calcite | Level 5

Hi RW / Jaap,

Well the issue is resolved and thanks for you both for quick reply.

Sorry Jaap while giving example i hgave incorrect Macroname, but in the process i used corret name. The issue with trim function using for all the macro variables, thanks RW.

Regards,

Venkat P

jakarman
Barite | Level 11

You are defining a macro named filecheck and than using one filecheck_create.  Getting an error that is most likely caused by unbalanced apostrophes. 

The things you have posted is inconsistent. Restart your eguide/sas-session and before submitting any code, review that carefully on colors indicating something coded badly.

---->-- ja karman --<-----
Tom
Super User Tom
Super User

From your error message it looks like you have unbalanced quotes somewhere in your program.

As to the idea of building up macro variable names (or any other string) from macro variables you just need to reference the variables in the right place.  For example if you want to build the value for the Tablename parameter from all of those other macro variables then just reference them in order.  Tablename=&ini._&Fcode._brow_&brand2._&season2._&work.

If that does not work (say because it is producing spaces in the middle of what should be a table name) then the problem is in the individual macro variables and should be fixed when they are created.

If what you wanted to build was not a table name, but instead the name of a macro variable that would actually hold the name of the table then you could add two extra &'s in front.  When SAS sees two adjacent &'s it resolves them to one & and then re-evaluates the results again for macro variable references.

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
  • 4 replies
  • 1098 views
  • 0 likes
  • 4 in conversation