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

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;
 
1 ACCEPTED SOLUTION

Accepted Solutions
KachiM
Rhodochrosite | Level 12

@Demographer 

 

Try

 

Test = vname(prob[i]);

View solution in original post

1 REPLY 1
KachiM
Rhodochrosite | Level 12

@Demographer 

 

Try

 

Test = vname(prob[i]);

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 connect to databases in SAS Viya

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.

Discussion stats
  • 1 reply
  • 578 views
  • 0 likes
  • 2 in conversation