01-04-2024
David_Billa
Rhodochrosite | Level 12
Member since
09-26-2019
- 667 Posts
- 482 Likes Given
- 1 Solutions
- 3 Likes Received
-
Latest posts by David_Billa
Subject Views Posted 871 01-04-2024 05:35 AM 898 01-04-2024 05:08 AM 1996 07-21-2023 07:29 AM 2020 07-21-2023 07:18 AM 1180 07-21-2023 06:36 AM 588 06-07-2023 02:56 PM 1100 06-01-2023 06:10 AM 5039 05-31-2023 03:38 PM 5060 05-31-2023 03:21 PM 5085 05-31-2023 03:11 PM -
Activity Feed for David_Billa
- Got a Like for In-database processsing Error. 11-22-2024 05:17 AM
- Posted Re: Query producing 0 row after having records in subquery on SAS Programming. 01-04-2024 05:35 AM
- Liked Re: Query producing 0 row after having records in subquery for yabwon. 01-04-2024 05:34 AM
- Posted Query producing 0 row after having records in subquery on SAS Programming. 01-04-2024 05:08 AM
- Liked Re: Aggregate in data step for ballardw. 07-24-2023 03:11 AM
- Liked Re: Aggregate in data step for Reeza. 07-24-2023 03:11 AM
- Posted Re: Aggregate in data step on SAS Programming. 07-21-2023 07:29 AM
- Posted Aggregate in data step on SAS Programming. 07-21-2023 07:18 AM
- Posted Macro parameter to repeat the value for n times on SAS Programming. 07-21-2023 06:36 AM
- Posted Proc Print on SAS Programming. 06-07-2023 02:56 PM
- Posted Re: Hex Format on SAS Programming. 06-01-2023 06:10 AM
- Liked Re: Special characters in IN operator for Reeza. 06-01-2023 01:27 AM
- Liked Re: Hex Format for Reeza. 06-01-2023 12:48 AM
- Liked Re: Hex Format for Tom. 06-01-2023 12:46 AM
- Liked Re: Hex Format for Reeza. 06-01-2023 12:45 AM
- Posted Re: Hex Format on SAS Programming. 05-31-2023 03:38 PM
- Posted Re: Hex Format on SAS Programming. 05-31-2023 03:21 PM
- Posted Re: Hex Format on SAS Programming. 05-31-2023 03:11 PM
- Posted Re: Hex Format on SAS Programming. 05-31-2023 03:02 PM
- Posted Re: Special characters in IN operator on SAS Programming. 05-31-2023 02:52 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 1 1 1 1 -
My Liked Posts
Subject Likes Posted 1 01-08-2020 02:19 AM 1 07-27-2022 12:54 PM 1 04-10-2022 08:22 AM
02-28-2023
01:29 PM
@Tom I think I'm missing something from your idea. I tried the following code by adding counter macro variable and it is errored. I don't see any delete and rename dataset step in your code.
Assume if we have three iterations and the value of 'counter' macro variable is also then i want to delete the already existing tables and rename the tables. This step also should execute three times after the value of macro variable is resolved to 3.
%if &nobs %then %do;
%let counter=%eval(&counter + (&sqlobs>0));
%put ####Counter=&counter.;
create table &prompt_table_name as
select * from connection to database(
select *
from &schema_temp..&prompt_tbl_name;
)
;
%end;
Error:
SYMBOLGEN: Macro variable NOBS resolves to 887
MLOGIC(TEST): %IF condition &nobs is TRUE
MLOGIC(TEST): %LET (variable name is COUNTER)
WARNING: Apparent symbolic reference COUNTER not resolved.
SYMBOLGEN: Macro variable SQLOBS resolves to 1
WARNING: Apparent symbolic reference COUNTER not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&counter + (1>0)
ERROR: The macro TEST will stop executing.
MLOGIC(TEST): Ending execution.
... View more
02-28-2023
01:18 PM
@Tom Your code is perfectly fine but it's complex for our project leader and also I was asked to create the index within proc only. Hence I tried the %do block which you see at last step but it's not working.
%let nobs=0;
select nobs format=32. into :nobs trimmed
from connection to database(
select count(*) as nobs from &schema_temp..&prompt_tbl_name
)
;
%if &nobs %then %do;
create table &prompt_tbl_name as
select * from connection to _snow_temp (
select *
from &schema_temp..&prompt_tbl_name;
)
;
%end;
%do i=1 %to %sysfunc(countw(¤t_distinct_var_list));
%let var=%scan(¤t_distinct_var_list,&i);
create index &var on &prompt_tbl_name(&var);;
%end;
Error message;
SYMBOLGEN: Macro variable CURRENT_DISTINCT_VAR_LIST resolves to bsc_division,ce_to_sud_mapping,product_family
WARNING: In a call to the COUNTW function or routine, the modifier "R" not valid.
WARNING: In a call to the COUNTW function or routine, the modifier "_" not valid.
WARNING: In a call to the COUNTW function or routine, the modifier "Y" not valid.
MLOGIC(TEST): %DO loop beginning; index variable I; start value is 1; stop value is 13; by value is 1.
MLOGIC(TEST): %LET (variable name is VAR)
SYMBOLGEN: Macro variable CURRENT_DISTINCT_VAR_LIST resolves to division,mapping,product
SYMBOLGEN: Macro variable I resolves to 1
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
ce_to_sud_mapping
ERROR: Argument 2 to macro function %SCAN is not a number.
ERROR: The macro TEST will stop executing.
... View more
02-28-2023
12:45 PM
@Tom In the below step we are checking the value of sqlobs and then doing the delete/rename for each iteration.
%if &sqlobs %then %do;
proc datasets lib=APP noprint;
delete &pmt_tbl_name;
change t_&pmt_tbl_name=&pmt_tbl_name;
quit;
;
Now I want to break that approach into parts. a) Check the value of sqlobs of each iteration. If it's greater than 0 then create one macro varible like % let counter=1.
If there are three iterations in the macro and if we have observations in the each of the dataset then value of counter macro varible should increase to 3. Now number of iterations is same as value of counter macro variable.
b) if the of number of iterations is equal to value of counter macro variable then execute the below step.
proc datasets lib=APP noprint;
delete &pmt_tbl_name;
change t_&pmt_tbl_name=&pmt_tbl_name;
quit;
... View more
02-28-2023
12:15 PM
I've the below macro code which create SAS dataset from database table and then I'm checking the record count and if it has record then it will drop and rename the SAS dataset. Instead of doing this record check and drop/rename the table for every iteration, I want to check the number of observations for each table and only if we there is record for all the tables then only drop/rename the table. Total number of SAS table creation is depends on the number of values in the macro variable 'type_lt'.
So after this line '%if &sqlobs %then %do;' I would like to know if we can create one more macro variable to add the counter when we have observation.of each APP.t_&pmt_tbl_name and when we have observations all the tables then I have to execute drop/rename step. I'm not certain if the proc datasets step move outside of the loop.
Assume we have four iterations for this macro then we have to drop/rename four datasets if we have obervation in APP.t_&pmt_tbl_name all the iterations. Any help?
% macro test;
proc sql;
%do type_id=1 %to %sysfunc(countw(&type_lt,,s));
........
%let sqlobs=0;
create table APP.t_&pmt_tbl_name as
select * from connection to database(
select distinct ¤t_distinct_var_list
from &schema_temp..&source_tbl
)
;
%if &sqlobs %then %do;
proc datasets lib=APP noprint;
delete &pmt_tbl_name;
change t_&pmt_tbl_name=&pmt_tbl_name;
quit;
;
%end;
quit;
;
%end;
.........
%mend;
%let type_lt =
a*b*c
d*e
e*f*g*h
a*g*i
;
%test(
type_lt = &type_lt
)
... View more
02-28-2023
08:48 AM
If I want to identify the number of observations from SAS datasets instead of database table then do we have any other method other than select count(*) to fit here?
When I tried the below method, I observed count(*) step is executing for longer time.
connect .... ;
create table WORK.t_&prompt_tbl_name as
select * from connection to database(
select distinct ¤t_distinct_var_list
from &schema_temp..&source_tbl
)
;
%let nobs=0;
select count(*) format=32. into :nobs trimmed
from WORK.t_&prompt_tbl_name
;
%if &nobs %then %do;
create table Libname.&prompt_tbl_name as
select * from connection to database(
select *
from &schema_temp..&prompt_tbl_name;
)
;
%end;
... View more
02-28-2023
04:22 AM
So, index is being retained after renaming the dataset name.
... View more
02-28-2023
03:34 AM
Yes I did this with one iteration before placing my code inside macro. I didn't realise that it will fail in macro looping. Now I'm not sure to correct it inside macro
... View more
02-28-2023
03:31 AM
There is outage time now due to licence renewal. In the interest of time, I'd like to know whether the index will be retained if we rename the dataset via proc datasets?
... View more
02-28-2023
03:28 AM
Thanks for the insights. Were you able to help me fix the issue? I'm not certain how to replace proc contents
... View more
02-28-2023
03:18 AM
I've tried the following program to create a index and I want to check whether index will be retained if we rename the dataset name which has index.
I observed that index is not being retained if we rename the dataset name. Is there a way to retain the index even if we rename the dataset name?
data cars;
set sashelp.cars;
run;
proc contents data=cars noprint
out=index_list(keep=libname memname name);
run;
filename code temp;
data _null_;
set index_list;
by libname memname ;
file code;
if first.libname then put 'proc datasets nolist lib=' libname ';' ;
if first.memname then put 'modify ' memname ';' / ' create index ' @;
put name @;
if last.memname then put ';' / 'run;' ;
if last.libname then put 'quit;' ;
run;
%include code/ source2;
data cars_new;
set cars;
run;
proc contents data=cars_new;
run;
proc contents data=cars;
run;
... View more
02-28-2023
03:15 AM
@yabwon Log is shown below. It's big file hence I shared only the portion of error log. Here the catch is index is created for all the iterations and from second iteration I could see the error before the index steps. However if I remove the index part from my code, it is executing without any issues for all the iteration.
SYMBOLGEN: Macro variable CLASS_VAR_ID resolves to 2
MLOGIC(SIMPLE_LOOP): %IF condition (&class_var_ID eq 1) is FALSE
MLOGIC(SIMPLE_LOOP): %LET (variable name is PROMPT_TBL_NAME)
SYMBOLGEN: Macro variable PROMPT_TBL_NAME resolves to dmm_tts_pt_div
SYMBOLGEN: Macro variable CURRENT_CLASS_VAR resolves to upn
MLOGIC(SIMPLE_LOOP): %DO loop index variable CLASS_VAR_ID is now 3; loop will not iterate again.
MLOGIC(SIMPLE_LOOP): %PUT NOTE: &=prompt_TBL_name
SYMBOLGEN: Macro variable PROMPT_TBL_NAME resolves to dmm_ttt_pt_div_upn
NOTE: PROMPT_TBL_NAME=dmm_ttt_pt_div_upn
NOTE: Line generated by the invoked macro "SIMPLE_LOOP".
235 execute( create or replace TBL &schema_temp..&prompt_TBL_name as select distinct
-------
180
235 ! ¤t_distinct_var_list from &schema_temp..&source_TBL ; ) by database;
SYMBOLGEN: Macro variable SCHEMA_TEMP resolves to PMQ_TEMP_TBLS
SYMBOLGEN: Macro variable PROMPT_TBL_NAME resolves to dmm_tts_pt_div_upn
SYMBOLGEN: Macro variable CURRENT_DISTINCT_VAR_LIST resolves to bss_division,upn
SYMBOLGEN: Macro variable SCHEMA_TEMP resolves to PMQ_TEMP_TBLS
SYMBOLGEN: Macro variable SOURCE_TBL resolves to dmm_transfer_prompts
MPRINT(SIMPLE_LOOP): execute( create or replace TBL PMQ_TEMP_TBLS.dmm_tts_pt_div_upn as select distinct bss_division,upn
from PMQ_TEMP_TBLS.dmm_transfer_prompts ;
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: Line generated by the invoked macro "SIMPLE_LOOP".
235 execute( create or replace TBL &schema_temp..&prompt_TBL_name as select distinct
235 ! ¤t_distinct_var_list from &schema_temp..&source_TBL ; ) by database;
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
MPRINT(SIMPLE_LOOP): ) by database;
... View more
02-28-2023
02:33 AM
When I execute the following code, it's works for first iteration and it's throwing an error from second iteration. I believe the issue is in the index portion (proc contents and data _null_). It's not working after first iteration. May be code placement is not right. Any help?
%macro simple_loop;
proc sql noprint;
connect using &db_lib as database;
%do type_id=1 %to %sysfunc(countw(&type_list,,s));
/*some macro code*/
execute(
create or replace tbl &schema_temp..&prompt_tbl_name as
select distinct ¤t_distinct_var_list
from &schema_temp..&source_tbl
;
) by database;
create tbl &prompt_tbl_name as
select * from connection to database (
select *
from &schema_temp..&prompt_tbl_name;
)
;
proc contents data=&prompt_tbl_name noprint
out=index_list(keep=libname memname name);
run;
filename code temp;
data _null_;
set index_list;
by libname memname ;
file code;
if first.libname then put 'proc datasets nolist lib=' libname ';' ;
if first.memname then put 'modify ' memname ';' / ' create index ' @;
put name @;
if last.memname then put ';' / 'run;' ;
if last.libname then put 'quit;' ;
run;
%include code / source2;
%end;
quit;
%mend simple_loop;
%simple_loop;
... View more
02-28-2023
01:56 AM
I've tried the following program to create a index and I want to check whether index will be retained if we rename the dataset name which has index.
I observed that index is not being retained if we rename the dataset name. Is there a way to retain the index even if we rename the dataset name?
data cars;
set sashelp.cars;
run;
proc contents data=cars noprint
out=index_list(keep=libname memname name);
run;
filename code temp;
data _null_;
set index_list;
by libname memname ;
file code;
if first.libname then put 'proc datasets nolist lib=' libname ';' ;
if first.memname then put 'modify ' memname ';' / ' create index ' @;
put name @;
if last.memname then put ';' / 'run;' ;
if last.libname then put 'quit;' ;
run;
%include code/ source2;
data cars_new;
set cars;
run;
proc contents data=cars_new;
run;
proc contents data=cars;
run;
... View more
02-27-2023
02:20 PM
Yes, I'm asking how to convert to proc sql. I will give a try as well.
... View more
02-27-2023
02:15 PM
I have not said that your solution has macro but other solution had. Anyway to convert your solution to proc sql without call execute? Sorry for too many restrictions.
... View more