<?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: How do I program the logic for this problem where I want the value to return back the var_name? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799986#M314619</link>
    <description>&lt;P&gt;Explain why row 1 results in rsn1, rsn2 when the Xs are in columns rsn1 and rsn3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the feeling that this is a situation where instead of all of this working with strings in a horizontal wide layout, your task and subsequent analysis would be much more easily performed if the data was in a long data set and instead of X or blank, you had 1s and 0s.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2022 22:19:12 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-03-03T22:19:12Z</dc:date>
    <item>
      <title>How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799984#M314617</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have1;
infile datalines dsd dlm=",";
	input id $ rsn1 $ rsn2 $ rsn3 $ rsn4 $ rsn5 $;
datalines;
001,X, ,X, , ,
002,X, , , , ,
003,, , , , ,
004,,X, , ,X,
;
run;

data want;
	set have1;
	
	overall_rsn=catx(" ,", rsn1, rsn2, rsn3, rsn4, rsn5);
	
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;How do I program this so that variable OVERALL_RSN shows the var_name for the actual value?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;For example, instead of observation 1 returning back "X, X" for OVERALL_RSN, I want it to return back "rsn1, rsn3".&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace" color="#000000"&gt;&lt;SPAN&gt;&lt;SPAN&gt;edit: The only solution that&amp;nbsp;I could come up with is this way. But the problem is the actual data set&amp;nbsp;I'm using has 30 Rsns variables, which could be quite burdensome for coding&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
	set have1;
	
	if rsn1="X" then rsn1="Rsn1";
	if rsn2="X" then rsn2="Rsn2";
	if rsn3="X" then rsn3="Rsn3";
	if rsn4="X" then rsn4="Rsn4";
	if rsn5="X" then rsn5="Rsn5";

	overall_rsn=catx(" ,", rsn1, rsn2, rsn3, rsn4);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799984#M314617</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-03-03T22:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799986#M314619</link>
      <description>&lt;P&gt;Explain why row 1 results in rsn1, rsn2 when the Xs are in columns rsn1 and rsn3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the feeling that this is a situation where instead of all of this working with strings in a horizontal wide layout, your task and subsequent analysis would be much more easily performed if the data was in a long data set and instead of X or blank, you had 1s and 0s.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799986#M314619</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-03T22:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799988#M314621</link>
      <description>Hi PaigeMiller,&lt;BR /&gt;&lt;BR /&gt;sorry I wrote this in haste and I changed the information. You are correct,, it should result in rsn1, rsn3 for obs. 1.&lt;BR /&gt;&lt;BR /&gt;I was given a data set like this. and I'm supposed to come up with a variable that lists only the reasons why, if there were reasons that exist.&lt;BR /&gt;&lt;BR /&gt;So are you saying I need to transform the data somehow?</description>
      <pubDate>Thu, 03 Mar 2022 22:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799988#M314621</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-03-03T22:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799993#M314625</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi PaigeMiller,&lt;BR /&gt;&lt;BR /&gt;sorry I wrote this in haste and I changed the information. You are correct,, it should result in rsn1, rsn3 for obs. 1.&lt;BR /&gt;&lt;BR /&gt;I was given a data set like this. and I'm supposed to come up with a variable that lists only the reasons why, if there were reasons that exist.&lt;BR /&gt;&lt;BR /&gt;So are you saying I need to transform the data somehow?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Okay, and what are you going to do with this data once you have converted observation 1 to be rsn1, rsn3? What is the next step? What is the next analysis or report or table? I'm not going down this path of string manipulation just yet, as I still think there are many easier ways to go.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799993#M314625</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-03T22:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799994#M314626</link>
      <description>That is the last step. Just to create a variable that displays the the list of Rsn's in a variable to display in a report. &lt;BR /&gt;&lt;BR /&gt;I came up with a long-hand solution that I edited in the OP, but it's fine when there is 4 variables. But in situations where I have 30 or more variables, that becomes a problem.</description>
      <pubDate>Thu, 03 Mar 2022 22:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799994#M314626</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-03-03T22:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799997#M314629</link>
      <description>&lt;LI-CODE lang="sas"&gt;Data have1;
infile datalines dsd dlm=",";
	input id $ rsn1 $ rsn2 $ rsn3 $ rsn4 $ rsn5 $;
datalines;
001,X, ,X, , ,
002,X, , , , ,
003,, , , , ,
004,,X, , ,X,
;
run;

data want;
	set have1;
      length overall_rsn $100.;
	array _rsn(*) rsn:;
	do i=1 to dim(_rsn);
        if _rsn(i) = 'X' then overall_rsn = catx(", ", overall_rsn, vname(_rsn(i)));
        end;
	
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799997#M314629</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-03-03T22:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799999#M314631</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have1;
infile datalines dsd dlm=",";
	input id $ rsn1 $ rsn2 $ rsn3 $ rsn4 $ rsn5 $;
datalines;
001,X, ,X, , ,
002,X, , , , ,
003,, , , , ,
004,,X, , ,X,
;
run;

data want;
  set have1;
  array rs rsn:;
  length rsn_list $40;
  do over rs;
    if not missing(rs) then rsn_list=catx(',',rsn_list,vname(rs));
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just make sure that the length of rsn_list is sufficient to hold a comma-separated list of all the variable names.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/799999#M314631</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-03T22:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800001#M314633</link>
      <description>&lt;P&gt;This is amazing. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 22:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800001#M314633</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-03-03T22:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800004#M314636</link>
      <description>Thanks, mkeintz, for this elegant solution!&lt;BR /&gt;&lt;BR /&gt;It was exactly what I needed.</description>
      <pubDate>Thu, 03 Mar 2022 22:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800004#M314636</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-03-03T22:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800014#M314641</link>
      <description>&lt;P&gt;First thing is convert the data to a usable structure using PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $ (rsn1-rsn5) (:$1.);
datalines;
001 X . X . .
002 X . . . .
003 . . . . .
004 . X . X .
;

proc transpose data=have out=tall;
  by id;
  var rsn1-rsn5 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could produce your report directly from that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set tall;
  by id;
  file print;
  if first.id then put id @;
  if col1='X' then put _name_ @;
  if last.id then put;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-03-03 191625.jpg" style="width: 320px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69129iDD70C1214400385C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-03-03 191625.jpg" alt="Screenshot 2022-03-03 191625.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Or you could build your long character string from it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (last.id);
    set tall;
    by id;
    length string $200;
    if col1='X' then string=catx(' ',string,_name_);
  end;
  drop _name_ col1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Mar 2022 00:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800014#M314641</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-04T00:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I program the logic for this problem where I want the value to return back the var_name?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800017#M314642</link>
      <description>Thanks for your help!</description>
      <pubDate>Fri, 04 Mar 2022 00:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-program-the-logic-for-this-problem-where-I-want-the/m-p/800017#M314642</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-03-04T00:36:40Z</dc:date>
    </item>
  </channel>
</rss>

