<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multiple If then else true conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526519#M143405</link>
    <description>&lt;P&gt;Hi ballard,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sorry, I guess without an example that code was not of much use. Please have a look at this. I provided a screenshot of Ex_2 dataset .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;BR /&gt;input id visit$ visit_num var1 var2 var3;&lt;BR /&gt;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Visit1 1 20 30 35&lt;BR /&gt;1 Visit2 2 75 35 45&lt;BR /&gt;2 Visit1 3 99 15 34&lt;BR /&gt;2 Visit2 4 55 38 48&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data ex_2;&lt;BR /&gt;set example;&lt;BR /&gt;by visit_num visit ;&lt;BR /&gt;if not(40&amp;lt;var1&amp;lt;70) then t1= catx(' ',"Score1",cats('(',var1,')'));&lt;BR /&gt;if not(40&amp;lt;var2&amp;lt;70) then t2= catx(' ',"Score2",cats('(',var2,')'));&lt;BR /&gt;if not(40&amp;lt;var3&amp;lt;70) then t3= catx(' ',"Score3",cats('(',var3,')'));&lt;BR /&gt;total = catx(' ',t1,t2,t3);&lt;BR /&gt;drop t1 t2 t3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So now my question is,&amp;nbsp;as you can see in the screenshot the highlighted row met both the conditions for&amp;nbsp;Score1 (75) Score2 (35) at&amp;nbsp;Visit2 for ID 1 so how can I code so that I get the output as below. Something like different score's that meet the conditions into different observation for a subject at that visit.Thanks in advance for the help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ID VISIT VISIT_NUM TOTAL&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; Visit2&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Score1(75)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; Visit2&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Score2(35)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jan 2019 22:40:18 GMT</pubDate>
    <dc:creator>Aidaan_10</dc:creator>
    <dc:date>2019-01-11T22:40:18Z</dc:date>
    <item>
      <title>Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526382#M143338</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I have&amp;nbsp; multiple if then else statements&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if educ = 0 then neweduc="&amp;lt; 3 yrs old";&lt;/P&gt;&lt;P&gt;else if educ=1 then neweduc="no school";&lt;/P&gt;&lt;P&gt;else if educ=2 then neweduc="nursery school";&lt;/P&gt;&lt;P&gt;else if educ in (15,16) then neweduc="Profess. degree";&lt;/P&gt;&lt;P&gt;else if educ in (15,17) then neweduc="Doctorate degree";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If suppose two or more conditions are true I want to display all of them by each Id how do I do that? In this way the with multiple if then else my values are overwritten if the first condition is true like 15 for '&lt;SPAN&gt;Profess. degree' and also the second one 15 for Doctorate so I want to display both the degrees in the output. Thanks for the help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output would be like:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EDU&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEWEDUC&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no school&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Profess. degree&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Doctorate degree&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 14:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526382#M143338</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2019-01-11T14:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526396#M143345</link>
      <description>&lt;P&gt;Write them out as separate categories.&amp;nbsp; Right now you have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if educ in (15,16) then neweduc="Profess. degree";&lt;/P&gt;
&lt;P&gt;else if educ in (15,17) then neweduc="Doctorate degree";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change that to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if educ = 15 then neweduc="Profess. degree, Doctorate";&lt;/P&gt;
&lt;P&gt;else if educ = 16 then neweduc="Profess. degree";&lt;/P&gt;
&lt;P&gt;else if educ = 17 then neweduc="Doctorate degree";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to assign NEWEDUC a long enough length before the IF/THEN statements.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 15:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526396#M143345</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-11T15:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526400#M143348</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174192"&gt;@Aidaan_10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I have&amp;nbsp; multiple if then else statements&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if educ = 0 then neweduc="&amp;lt; 3 yrs old";&lt;/P&gt;
&lt;P&gt;else if educ=1 then neweduc="no school";&lt;/P&gt;
&lt;P&gt;else if educ=2 then neweduc="nursery school";&lt;/P&gt;
&lt;P&gt;else if educ in (15,16) then neweduc="Profess. degree";&lt;/P&gt;
&lt;P&gt;else if educ in (15,17) then neweduc="Doctorate degree";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If suppose two or more conditions are true I want to display all of them by each Id how do I do that? In this way the with multiple if then else my values are overwritten if the first condition is true like 15 for '&lt;SPAN&gt;Profess. degree' and also the second one 15 for Doctorate so I want to display both the degrees in the output. Thanks for the help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The desired output would be like:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EDU&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NEWEDUC&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no school&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Profess. degree&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Doctorate degree&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should provide example of the input data.&lt;/P&gt;
&lt;P&gt;It appears that you want may want to create a new record for an id when educ= 15 (Only?). Is that correct.&lt;/P&gt;
&lt;P&gt;Also, what do you want when educ is something other thatn 0,1,2,15, 16 and 17?&lt;/P&gt;
&lt;P&gt;Typically I might use a custom format to assign values as needed but ince you are doing something different with one specific value the format approach likely would not work.&lt;/P&gt;
&lt;P&gt;I think a SELECT when block&amp;nbsp;works for this.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   length neweduc $ 20;
   select (educ);
      when (0) neweduc="&amp;lt;3 years old";
      when (1) neweduc="no school";
      when (2) neweduc="nursery school";
      when (15) do; neweduc='Profess. degree';output;
                    neweduc='Doctorate degree';
               end;
      when (16) neweduc='Profess. degree';
      when (17) neweduc='Doctorate degree';
      otherwise;/* what ever you may want to do when none of the above
                 values are encountered*/
   end;
   /* this output is needed because of the explicit output in 
     the when(15)for the first value*/
   output;
run;&lt;/PRE&gt;
&lt;P&gt;SELECT evaluates the value in the () then branches to the When statement with that value. You can have multiple values in a when such as when( 4,5,6). Notice that "then" is not used to do the assignment. You can have a block of instructions inside a do/end block of code as for the when (15). A value may only occur in a single WHEN. The OTHERWISE is to execute code for any values not explicitly listed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you also need to state the length of the variable before use in this case. Your code would set the length&amp;nbsp; of neweduc to 10 characters because the first use is in the neweduc="&amp;lt; 3 yrs old"; The length would be long enough to hold all of the values you use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are other ways to use select but this should work for what I think you are attempting.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 16:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526400#M143348</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-11T16:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526434#M143358</link>
      <description>&lt;P&gt;Hi ballard,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I tried using select when also.. it did not work. I got the results using a lot of if then else statements and I am using 3 variables here but I have&amp;nbsp; several variables in my data..so I was looking for an alternate effective method. Please have a look at what I have used. As I have used different combinations of variables to check the condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) and ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) and ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .)&lt;BR /&gt;then&lt;BR /&gt;Total&amp;nbsp;= ('Score1" || " (" || strip(var1) || ")" )||&lt;BR /&gt;( "Score2" || " (" || strip(var2) || ")" ||&lt;BR /&gt;( "Score3" || " (" || strip(var3) || ")"&amp;nbsp;&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;/***here I concatenated the score's in one single variable and I got the result like total=Score1(45) Score2(20) Score3(38)&lt;/P&gt;&lt;P&gt;but I want to see all 3 score's if they exist for a ID in different rows as&amp;nbsp;below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OBS&amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; TOTAL&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; Subject1 SCORE1(45)&lt;/P&gt;&lt;P&gt;2)&amp;nbsp;&lt;SPAN&gt;Subject1&amp;nbsp; SCORE2(20)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3)&amp;nbsp;&lt;SPAN&gt;Subject1&amp;nbsp; SCORE3(38)&amp;nbsp; ***/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Else&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) and ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) then&lt;BR /&gt;total&amp;nbsp;= ("Score1" || " (" || strip(var1) || ")")||&lt;BR /&gt;("Score2" || " (" || strip(var2) || ")" ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Else&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) and ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .)&lt;BR /&gt;then&lt;BR /&gt;Total&amp;nbsp;= ('Score1" || " (" || strip(var1) || ")" )||&lt;BR /&gt;(' Score3" || " (" || strip(var3) || ")"&amp;nbsp; )&lt;BR /&gt;;&lt;BR /&gt;Else&lt;BR /&gt;if ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) and ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .)&lt;BR /&gt;then&lt;BR /&gt;Total&amp;nbsp;= ( "Score2" || " (" || strip(var2) || ")") ||&lt;BR /&gt;(" Score3" || " (" || strip(var3) || ")"&amp;nbsp; )&lt;BR /&gt;;&lt;BR /&gt;Else&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) then&lt;BR /&gt;Total&amp;nbsp;= " Score1" || " (" || strip(var1) || ")" ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Else if ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) then&lt;/P&gt;&lt;P&gt;Total&amp;nbsp;= "Score2" || " (" || strip(var2) || ")"&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Else if ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .) then&lt;BR /&gt;Total =&amp;nbsp; " Score3" || " (" || strip(var3) || ")" ;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 17:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526434#M143358</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2019-01-11T17:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526442#M143361</link>
      <description>&lt;P&gt;If you have many categories your code will be hard to maintain if you use the if-else approach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* my solution;

data degree;
	length degree $20.;
	infile datalines dsd;
	input degree $ educ $;
	datalines;
"&amp;lt; 3 yrs old",0
"no school",1
"nursery school",2
"Profess. degree",15 16
"Doctorate degree",15 17
;
run;

data person;
	input id educ;
	datalines;
1 1
2 15
3 17
4 15
;
run;

data degree;
	set degree(rename=(educ=educ_old));
	drop nwords i educ_old;
	nwords=countw(educ_old);
	do i=1 to nwords;
		educ=input(scan(educ_old, i), 2.);
		output;
	end;
run;


proc sql;
	create table sol_1 as
		select person.*, degree.degree
		from person natural join degree;
quit;
proc print; title 'sol 1'; * (sol 1);


* if you don't want to use sql/join;
proc sort data=degree; by educ;
data degree;
	length degree $40.;
	retain degree;
	drop degree_old;
	set degree(rename=(degree=degree_old));
	by educ;
	if first.educ then degree=degree_old;
	else degree=catx('; ', degree, degree_old);
	if last.educ then output;
run;
proc sort data=person; by educ;


data sol_2;
	merge person(in=in_person) degree;
	by educ; if in_person;
run;

proc print; title 'sol 2'; * which could serve your purposes (sol2);

data sol_3;
	merge person(in=in_person) degree;
	by educ; if in_person;
	retain degrees;
	drop degrees nword i;
	if first.educ then degrees=degree;
	nword=countw(degrees, ';');
	do i=1 to nword;
		degree=scan(degrees, i, ';');
		output;
	end;
run;

proc print; title 'sol 3';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which produces this output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="save_test.jpg" style="width: 336px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26202i6B7C0B03F4847666/image-size/large?v=v2&amp;amp;px=999" role="button" title="save_test.jpg" alt="save_test.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Notice solution 3 might fail if you have many records per person; in that case, it would need additional tuning;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 18:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526442#M143361</guid>
      <dc:creator>franriv</dc:creator>
      <dc:date>2019-01-11T18:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526505#M143397</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174192"&gt;@Aidaan_10&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi ballard,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I tried using select when also.. it did not work. I got the results using a lot of if then else statements and I am using 3 variables here but I have&amp;nbsp; several variables in my data..so I was looking for an alternate effective method. Please have a look at what I have used. As I have used different combinations of variables to check the condition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show the code that used when you tried SELECT.&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) and ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) and ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .)&lt;BR /&gt;then&lt;BR /&gt;Total&amp;nbsp;= ('Score1" || " (" || strip(var1) || ")" )||&lt;BR /&gt;( "Score2" || " (" || strip(var2) || ")" ||&lt;BR /&gt;( "Score3" || " (" || strip(var3) || ")"&amp;nbsp;&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;/***here I concatenated the score's in one single variable and I got the result like total=Score1(45) Score2(20) Score3(38)&lt;/P&gt;
&lt;P&gt;but I want to see all 3 score's if they exist for a ID in different rows as&amp;nbsp;below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OBS&amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; TOTAL&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp; Subject1 SCORE1(45)&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;&lt;SPAN&gt;Subject1&amp;nbsp; SCORE2(20)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3)&amp;nbsp;&lt;SPAN&gt;Subject1&amp;nbsp; SCORE3(38)&amp;nbsp; ***/&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Else&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) and ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) then&lt;BR /&gt;total&amp;nbsp;= ("Score1" || " (" || strip(var1) || ")")||&lt;BR /&gt;("Score2" || " (" || strip(var2) || ")" ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Else&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) and ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .)&lt;BR /&gt;then&lt;BR /&gt;Total&amp;nbsp;= ('Score1" || " (" || strip(var1) || ")" )||&lt;BR /&gt;(' Score3" || " (" || strip(var3) || ")"&amp;nbsp; )&lt;BR /&gt;;&lt;BR /&gt;Else&lt;BR /&gt;if ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) and ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .)&lt;BR /&gt;then&lt;BR /&gt;Total&amp;nbsp;= ( "Score2" || " (" || strip(var2) || ")") ||&lt;BR /&gt;(" Score3" || " (" || strip(var3) || ")"&amp;nbsp; )&lt;BR /&gt;;&lt;BR /&gt;Else&lt;BR /&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .) then&lt;BR /&gt;Total&amp;nbsp;= " Score1" || " (" || strip(var1) || ")" ;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Else if ( (var2&amp;lt;70 and var2&amp;lt;40) and var2&amp;gt; .) then&lt;/P&gt;
&lt;P&gt;Total&amp;nbsp;= "Score2" || " (" || strip(var2) || ")"&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Else if ( (var3&amp;lt;70 and var3&amp;lt;40) and var3&amp;gt; .) then&lt;BR /&gt;Total =&amp;nbsp; " Score3" || " (" || strip(var3) || ")" ;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A general comment on the above code:&lt;/P&gt;
&lt;PRE&gt;if ( (var1&amp;lt;70 and var1&amp;lt;40) and var1&amp;gt; .)&lt;/PRE&gt;
&lt;P&gt;The &amp;lt;70 part is not contributing to your results as anything &amp;lt;40 is also less than 70. In effect you are only selecting values less than 40. Was that the intent? If so&amp;nbsp; (. &amp;lt; var1 &amp;lt;40) would be more appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to look at the concatenation functions CATX, CATS and CATT instead of using the || operator.&lt;/P&gt;
&lt;PRE&gt;Total = ('Score1" || " (" || strip(var1) || ")" )||
( "Score2" || " (" || strip(var2) || ")" ||
( "Score3" || " (" || strip(var3) || ")" 
;&lt;/PRE&gt;
&lt;P&gt;by using one of the concatenation functions. Also the first quote as a ' , single quote, followed by a bunch of " means that there are unbalanced quotes in that statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Total= catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;' '&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;"Score1"&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'('&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,var1,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;')'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;"Score2"&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'('&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,var2,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;')'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;),&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;"Score3"&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'('&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,var3,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;')'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;which should also not generate messages in the log about conversion to character values.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Also the code you post actually bares little resemblance to the if/then/else you started with as you are now involving multiple different variables.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Also please describe what you mean by "I want to see all 3 score's if they exist for a ID in different rows as&amp;nbsp;below". Do want a single value that will, when printed attempt to add lines like the (ever hateful to data users) Excel Alt-Enter between values in a cell?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;That would require adding something between values and depends greatly on what procedures you are going to use to display the value.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;If this were my code I would create 3 temporary total variables and then concatenate them together something like:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I don't really know what you meant using 70 above and none of the code you showed would have a result for values between 70 and 40 so don't really have much range for the values other than one greater than 70 that gets excluded as your code would have.&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;data example;
   input var1 var2 var3;
   if .&amp;lt;var1&amp;lt;40 then t1= catx(' ',"Score1",cats('(',var1,')'));
   if .&amp;lt;var2&amp;lt;40 then t2= catx(' ',"Score2",cats('(',var2,')'));
   if .&amp;lt;var3&amp;lt;40 then t3= catx(' ',"Score3",cats('(',var3,')'));
   total = catx(' ',t1,t2,t3);
   drop t1 t2 t3;
datalines;
20 30  35
.  25  .
15 .   99
;
run;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 21:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526505#M143397</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-11T21:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526507#M143399</link>
      <description>Sorry about the typo error of &amp;lt; 70 its actually &amp;gt;70 and there are double quotes in my data...its just while typing here to provide example I typed wrong..</description>
      <pubDate>Fri, 11 Jan 2019 21:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526507#M143399</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2019-01-11T21:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526519#M143405</link>
      <description>&lt;P&gt;Hi ballard,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sorry, I guess without an example that code was not of much use. Please have a look at this. I provided a screenshot of Ex_2 dataset .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;BR /&gt;input id visit$ visit_num var1 var2 var3;&lt;BR /&gt;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Visit1 1 20 30 35&lt;BR /&gt;1 Visit2 2 75 35 45&lt;BR /&gt;2 Visit1 3 99 15 34&lt;BR /&gt;2 Visit2 4 55 38 48&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data ex_2;&lt;BR /&gt;set example;&lt;BR /&gt;by visit_num visit ;&lt;BR /&gt;if not(40&amp;lt;var1&amp;lt;70) then t1= catx(' ',"Score1",cats('(',var1,')'));&lt;BR /&gt;if not(40&amp;lt;var2&amp;lt;70) then t2= catx(' ',"Score2",cats('(',var2,')'));&lt;BR /&gt;if not(40&amp;lt;var3&amp;lt;70) then t3= catx(' ',"Score3",cats('(',var3,')'));&lt;BR /&gt;total = catx(' ',t1,t2,t3);&lt;BR /&gt;drop t1 t2 t3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So now my question is,&amp;nbsp;as you can see in the screenshot the highlighted row met both the conditions for&amp;nbsp;Score1 (75) Score2 (35) at&amp;nbsp;Visit2 for ID 1 so how can I code so that I get the output as below. Something like different score's that meet the conditions into different observation for a subject at that visit.Thanks in advance for the help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ID VISIT VISIT_NUM TOTAL&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; Visit2&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Score1(75)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; Visit2&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Score2(35)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 22:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526519#M143405</guid>
      <dc:creator>Aidaan_10</dc:creator>
      <dc:date>2019-01-11T22:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526530#M143412</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data example;
	input id visit$ visit_num var1 var2 var3;
	datalines;
1 Visit1 1 20 30 35
1 Visit2 2 75 35 45
2 Visit1 3 99 15 34
2 Visit2 4 55 38 48
;
run;


data ex_2;
	set example;
	array my_arr[3] var1-var3;
	do i=1 to 3;
		if not(40&amp;lt;my_arr[i]&amp;lt;70) then
		do;
			TOTAL=cats("Score",i,'(',my_arr[i],')');
			output;
		end;
	end;
	drop var1-var3 i;
run;

proc print;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="xxans.jpg" style="width: 259px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26211i96D9EA8AB72A7FDA/image-size/large?v=v2&amp;amp;px=999" role="button" title="xxans.jpg" alt="xxans.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jan 2019 23:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526530#M143412</guid>
      <dc:creator>franriv</dc:creator>
      <dc:date>2019-01-11T23:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple If then else true conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526539#M143415</link>
      <description>&lt;P&gt;Okay now that we have some clarity of output. Two possibly approaches depending on range of values:&lt;/P&gt;
&lt;P&gt;Quite often moderately complex logic involving a single variable can be solved with a custom format.&lt;/P&gt;
&lt;PRE&gt;Proc format library=work;
picture score  (default=11)
0 -&amp;lt; 40 = "09)" (prefix="Score (")
70 &amp;lt;- 100 = "009)" (prefix="Score (")
other=" "
;
run;

data example;
input id visit$ visit_num var1 var2 var3;
/* string manipulation approach*/
   length t1 t2 t3 $ 11;
/*   if (.&amp;lt;var1&amp;lt;40) or var1&amp;gt;70 then t1= catx(' ',"Score1",cats('(',var1,')'));*/
/*   if (.&amp;lt;var2&amp;lt;40) or var2&amp;gt;70 then t2= catx(' ',"Score2",cats('(',var2,')'));*/
/*   if (.&amp;lt;var3&amp;lt;40) or var3&amp;gt;70 then t3= catx(' ',"Score3",cats('(',var3,')'));*/
/* use of a format*/
   t1=put(var1,score.);
   t2=put(var2,score.);
   t3=put(var3,score.);
   tt = catx('|',t1,t2,t3);
   drop t1 t2 t3 tt i;
   do i= 1 to countw(tt,'|');
      total=scan(tt,i,'|');
      output;
   end;
      
datalines;
1 Visit1 1 20 30 35
1 Visit2 2 75 35 45
2 Visit1 3 99 15 34
2 Visit2 4 55 38 48
3 Visit1 5 . . .
3 Visit1 6 100 . .
;
run;

&lt;/PRE&gt;
&lt;P&gt;I commented out an approach using direct sting manipulation to show the correct logic for your range selection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Proc format values list used by Picture, value and invalue statements can use&amp;nbsp; a &amp;lt;- b, a-b, a-&amp;lt;b or a&amp;lt;-&amp;lt;b which correspond to intervals of (a,b] [a,b] [a,b) and (a,b) where [ or ] indicate the boundary value is included and ( or ) indicate the boundary value is excluded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You did not indicate the maximum value a score might have. The format I defined only goes to 100. If you need larger values then increase 100 to that value. If you need more than 3 digits then you will need to add additional 0 before the 009 to match that length and you should increase the (default= ) value to match the increased characters. The default indicates the default length of a result if a length is not assigned to a target variable. The prefix tells the format to place that text in front of the resolved format value, the 09 and 009 are digit selectors, the 0 are optional and the 9(or any digit except 0)&amp;nbsp;indicates a required value. If you have additional 9 in the format and the value won't fill the picture such as a value of 2 with a '99' digit selector you get a leading 0 displayed: 02. The ) after the 9 is the last character to display.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jan 2019 00:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-If-then-else-true-conditions/m-p/526539#M143415</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-12T00:45:55Z</dc:date>
    </item>
  </channel>
</rss>

