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

Dear All,

 

I have a program like below , which is to modify the labels of the datasets.

 


proc sql noprint;
select distinct quote(trim(memname)) into :mis_tables SEPARATED by ',' from sashelp.vcolumn
where libname='libref';
quit;
%put &mis_tables;

options nomlogic nosymbolgen nomprint;

/* Updating the lables */
%macro s(kname1 ,kname2,labels );
%let labels2 = %sysfunc(tranwrd(%quote(&labels),%str(??),%str(,)));

proc datasets lib=resasdmc nodetails nolist ;
modify &kname1;
label &kname2="&labels2" ;
quit;
%mend s;

data ddd(keep=table_name tech_name label_name_1);
set mis_ref_labels; //oracle table
where table_name in (&mis_tables);
label_name_1= tranwrd (label_name,',','??');
run;

data _null_;
set ddd;
call execute('%nrstr(%s('||(strip(table_name))||' , '||(strip(tech_name))||','||%str(strip(label_name_1))||'))');
run;

 

Table ddd:

TABLE_NAMETECH_NAMElabel_name_1
MIS_FLAT_BUS_SEG_KPIAMT0_AAE_NAcq Cost And Admin Exp?? Net
MIS_FACTAMT0_AAE_OAcq Cost And Admin Exp?? Retro
MIS_FACTAMT1_APR_NAgg Pol Res?? Net
MIS_BUS_COND_DEDUCTIONSADDCOMM_AMOUNTADDCOMM_AMOUNT
MIS_BUS_COND_DEDUCTIONSADDCOMM_AMOUNT_MAINADDCOMM_AMOUNT_MAIN
MIS_BUS_COND_DEDUCTIONSADDCOMM_DEDBASISADDCOMM_DEDBASIS
MIS_BUS_COND_DEDUCTIONSADDCOMM_DEDUCTION_TABADDCOMM_DEDUCTION_TAB
MIS_BUS_COND_DEDUCTIONSADDCOMM_FK_AMT_CYADDCOMM_FK_AMT_CY
MIS_BUS_COND_DEDUCTIONSADDCOMM_METHOD_IDADDCOMM_METHOD_ID
MIS_BUS_COND_DEDUCTIONSADDCOMM_METHOD_TITLEADDCOMM_METHOD_TITLE
MIS_BUS_COND_DEDUCTIONSADDCOMM_PCTManagement Expense (%)

 

I am gettign an error :

ERROR: Expected close parenthesis after macro function invocation not found.

 

Rootcause : The last row, label_name1 column is having a value Management Expense (%) where the character '%)' is masking ')'., there by causes closing parenthesis issue.

 

Can anyone please help here?

 

Thanks,

Chithra

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You can modify the data step to execute only one proc datasets:

data _null_;
set ddd end=done;
by table_name;
if _n_ = 1 then call execute('
  proc datasets lib=resasdmc nodetails nolist;
');
if first.table_name then call execute('
  modify ' !! strip(table_name) !! ';
');
call execute('
  label ' !! strip(tech_name) !!'="' !! strip(label_name) '";
');
if done then call execute('quit;');
run;

View solution in original post

9 REPLIES 9
Kurt_Bremser
Super User

Why don't you put everything into the call execute:

data ddd(keep=table_name tech_name label_name);
set mis_ref_labels; //oracle table
where table_name in (&mis_tables);
run;

data _null_;
set ddd;
call execute('
  proc datasets lib=resasdmc nodetails nolist;
  modify ' !! strip(table_name) !! ';
  label ' !! strip(tech_name) !!'="' !! strip(label_name) '";
  quit;
');
run;

 

 

Edit: removed the surplus quote, as found by @chithra  

chithra
Quartz | Level 8

will this solves the issue?

it is throwing erro for mw..quotes issue.

chithra
Quartz | Level 8

it was a bracket issue in the code you provided..

corercted it now..

 

do you have any idea to increase the performance.

There are 4000 datasets.

Kurt_Bremser
Super User

You can modify the data step to execute only one proc datasets:

data _null_;
set ddd end=done;
by table_name;
if _n_ = 1 then call execute('
  proc datasets lib=resasdmc nodetails nolist;
');
if first.table_name then call execute('
  modify ' !! strip(table_name) !! ';
');
call execute('
  label ' !! strip(tech_name) !!'="' !! strip(label_name) '";
');
if done then call execute('quit;');
run;
chithra
Quartz | Level 8

Thank you.

And i am getting an error below :

ERROR: The value ' 'n is not a valid SAS name.

Kurt_Bremser
Super User

I guess you have an empty table_name or tech_name. Or some other "funny" value.

Please post the log of the code lines that cause the value; just posting the message is not helpful.

chithra
Quartz | Level 8

label_name =

99.5%  Value At Risk (Lifeup)

 

This value is causing the issue..'%' character

Tom
Super User Tom
Super User

Better to use functions to insure that the generated code has valid syntax. Use NLITERAL() to handle gooty variable names. Use QUOTE() to quote the labels using single quotes to prevent any embedded macro triggers or quote characters from causing trouble.

 

data ddd ;
  set mis_ref_labels(keep= table_name tech_name label_name) end=eof; 
  where table_name in (&mis_tables);
  by table_name ;
  if _n_=1 then call execute('proc datasets lib=resasdmc nolist;');
  if first.table_name then call execute(catx(' ','modify',nliteral(table_name),';'));
  call execute(catx(' ','label',nliteral(tech_name),'=',quote(trim(label_name),"'"),';'));
  if last.table_name then call execute('run;');
  if eof then call execute('quit;');
run;
chithra
Quartz | Level 8

Many Thanks.

It is working now !

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 9 replies
  • 921 views
  • 4 likes
  • 3 in conversation