Insert and update using proc sql simultaneously in SAS -


i importing file using proc import

proc import datafile="/opt/export_d.csv" replace out=work.export_data; run; 

then selected 2 variables exported table having condition proc sql;

create table work.login2 select ' survey_id'n, time format=datetime20.,' username'n work.export_data having time=max(time) , ' username'="sasdemo"; quit; 

then created macro survey_id because have update value survey_id reference in different table shown in below code:

proc sql; select max(' survey_id'n) into: sid work.login2; quit; 

now if id blank don't have insert if have survey_id have update few columns in table using below code not happening.

proc sql; case when ' survey_id'n not null update table_name set sas_tracking_code="&trackingcode." survey_id=&sid. else end; quit; 

the syntax in proc sql not valid. @ all. case whencan used within statemements select, where, order by. following update if survey_id not blank:

proc sql;   update table_name   set sas_tracking_code="&trackingcode"   survey_id=&sid. , survey_id not null   ; quit; 

if want execute update only when condition true, should use macro.

edit: macro this:

%macro update;   %if %symexist(sid) , not &sid = %then %do;    proc sql;       update table_name       set sas_tracking_code="&trackingcode"       survey_id=&sid.       ;     quit;   %end; %mend; 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -