BookmarkSubscribeRSS Feed
Kanyange
Fluorite | Level 6

Hi , I was trying to run the code below but get an error from SAS . I have attache the error I get as it is a long one..Basically it says Failed to transcode data from U_UTF8_CE to U_LATIN1_CE enconding because it contained characters which arenot supported by your SAS session encoding. A portion of the source string, in hex representation is [None] 2ae03e396874 : 3b 2a 27 3b 2a 22 2a 2f 3b 71 75 69 74 3b 72 |;*;*/; quit; r| Some code points did not transcode etc.. Below is the code that's giving me errors

1 REPLY 1
Kanyange
Fluorite | Level 6

Sorry this is the code that's creating errors /**********************************/ /*INFORMATION VALUE CALCULATION*/ /*******************************/ DATA META_VARIABLESET;   SET EMWS2.META_VARIABLESET    (KEEP=NAME NEWROLE);   WHERE NEWROLE NE 'REJECTED'; RUN; proc sql noprint;     select distinct name into :all_vars separated by ' ' from META_VARIABLESET; select count(*) into :num_vars from META_VARIABLESET; quit; %put There are --&num_vars.-- variables, listed below...; %put --&all_vars.--; /********************************/ /*Information Value Calculation*/ /******************************/ /* Check levels */ %let tiers = 10; ods output nlevels=checkfreq; proc  freq data=TRAINING nlevels; tables &all_vars. /noprint; run ; ods output close;   data  usevars; set checkfreq; where nlevels >= &tiers.; row_num = _n_; length str_var $34; str_var = strip(cat("'", strip(tablevar), "'")); run ; %macro woe_prep; proc sql noprint; select count(*) into :max_iters from usevars; quit; %put &max_iters.; %do i = 1 %to &max_iters.; proc sql noprint; select tablevar, str_var into :a, 😛 from usevars where row_num = & i.; quit; %let this_var = &a.; %let str_var = &b.; %put &this_var.; %put &str_var.; data temp; length tablevar $32.; set TRAINING (keep = TARGET &this_var.); tablevar = & str_var.; run; proc rank data=temp out=temp groups=& tiers.; var & this_var.; ranks var_rank; run; proc sql; create table temp2 as select tablevar, var_rank, avg(& this_var.) as mean_origv, min(& this_var.) as min_origv, max(& this_var.) as max_origv, count(*) as custs, sum(case when target = 1 then 1 else 0 end) as good, sum(case when target = 0 then 1 else 0 end) as bad, sum(case when & this_var. = . then 1 else 0 end) as miss_val from temp group by 1, 2 order by 1, 2; quit; %if &i. = 1 %then %do; data outstack; set temp2; run; %end; %if &i. >= 2 %then %do; data outstack; set outstack temp2; run; %end; %end; %mend woe_prep;   %woe_prep;   proc sql; create table outstack_tots as select tablevar, sum(custs) as tot_custs, sum(good) as tot_good, sum(bad) as tot_bad, sum(miss_val) as tot_miss from outstack group by 1 order by 1; quit ;   proc sort data=outstack; by tablevar var_rank; run ; proc sort data=outstack_tots; by tablevar; run ;   data woe; merge outstack outstack_tots; by tablevar; dist_good = good / tot_good; dist_bad = bad / tot_bad; woe = log(dist_good / dist_bad) * 100; pre_iv = (dist_good - dist_bad) * log(dist_good / dist_bad); run ;   proc sql; create table iv as select tablevar, sum(pre_iv) as iv, sum(good) as tot_good, sum(bad) as tot_bad, sum(custs) as tot_custs, sum(miss_val) as tot_miss from woe group by 1 order by 2 desc; quit ;       proc npar1way data=MT.BNA_HC_BGRE_BUILD_BALANCED edf noprint; var &all_vars.; class target; output out=ks_out (keep= _var_ _D_ rename=(_var_=tablevar _D_=ks)); run ; proc sort data=ks_out; by tablevar; run ; proc sort data=iv; by tablevar; run ;   data &init._iv_&model._&vers.; merge iv (in=a) ks_out; by tablevar; if a = 1; run ;   proc sort data=&init._iv_&model._&vers.; by descending iv; run

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 806 views
  • 0 likes
  • 1 in conversation