Hi,
In the following codes, the variable test must have the label of the corresponding variable in the array "prob" when the if conditions is met. For instance, if the first condition is met for i=1, then the value for the variable test should be "AN_urban". If it's the second statement is true, then the value of test should be "AD_uban".
data work.pop_dm;
merge work.pop_2010(in=in1) work.dom_mig;
by region agegr edu sex year;
if in1;
a=rand('uniform');
array prob {*} AN_urban AD_urban AR_urban AS_urban BR_urban CH_urban CT_urban DN_urban DD_urban DL_urban GA_urban GJ_urban HR_urban HP_urban JK_urban JH_urban KA_urban KL_urban LD_urban MP_urban MH_urban MN_urban ML_urban MZ_urban NL_urban OR_urban PY_urban PB_urban RJ_urban SK_urban TN_urban TR_urban UT_urban UP_urban WB_urban AN_rural AD_rural AR_rural AS_rural BR_rural CH_rural CT_rural DN_rural DD_rural DL_rural GA_rural GJ_rural HR_rural HP_rural JK_rural JH_rural KA_rural KL_rural LD_rural MP_rural MH_rural MN_rural ML_rural MZ_rural NL_rural OR_rural PY_rural PB_rural RJ_rural SK_rural TN_rural TR_rural UT_rural UP_rural WB_rural;
do i=1 to dim(prob);
if i=1 and a<prob(i) then test="LABEL OF PROB";
if prob(i)<=a<prob(i+1) then test="LABEL OF PROB+1";
end;
run;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.