<?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: Creating contextual variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558809#M10167</link>
    <description>Yes, there can be some missing values. I forgot to mention that.</description>
    <pubDate>Wed, 15 May 2019 06:19:14 GMT</pubDate>
    <dc:creator>Sledgehamma</dc:creator>
    <dc:date>2019-05-15T06:19:14Z</dc:date>
    <item>
      <title>Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558615#M10131</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to SAS and I'm trying to do the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;based upon whats inside each observation I want to create a new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is structured as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; var1 &amp;nbsp;&amp;nbsp; var2 &amp;nbsp;&amp;nbsp; var3&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; x:1 &amp;nbsp; &amp;nbsp; &amp;nbsp; y:1 &amp;nbsp; &amp;nbsp; z:5&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; z:3 &amp;nbsp; &amp;nbsp; &amp;nbsp; y:7 &amp;nbsp; &amp;nbsp; x:5&lt;BR /&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; x:9 &amp;nbsp; &amp;nbsp; &amp;nbsp; y:4 &amp;nbsp; &amp;nbsp; z:4&lt;BR /&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; y:1 &amp;nbsp; &amp;nbsp; &amp;nbsp; z:1 &amp;nbsp; &amp;nbsp; x:5&lt;BR /&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; y:2 &amp;nbsp; &amp;nbsp; &amp;nbsp; x:15 &amp;nbsp; z:9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;where x may be $sum of investments, y may be interest rates and so on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;The data is very unstructured so that var1 has bascially no meaning as it can include values for x,y and z. So my goal is a strucutred data such that:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;&amp;nbsp; x &amp;nbsp; &amp;nbsp;&amp;nbsp; y &amp;nbsp; &amp;nbsp; z&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 5 &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;&amp;nbsp; 9 &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;4 &amp;nbsp; &amp;nbsp;&amp;nbsp; 5 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;5 &amp;nbsp;&amp;nbsp; 15 &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm thankfull for every input.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 13:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558615#M10131</guid>
      <dc:creator>Sledgehamma</dc:creator>
      <dc:date>2019-05-14T13:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558618#M10133</link>
      <description>&lt;P&gt;You say that your data is unstructured.. But do you have x, y and z in each of your observations? Or do you have observations with missing values or where eg y appears twice?&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 13:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558618#M10133</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-14T13:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558619#M10134</link>
      <description>&lt;P&gt;Assume I understood your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     (var1    var2    var3 ) ($);
cards;
1       x:1       y:1     z:5
2       z:3       y:7     x:5
3       x:9       y:4     z:4
4       y:1       z:1     x:5
5       y:2       x:15   z:9
;
run;
data temp;
 set have;
 array x{*} $ var:;
 do i=1 to dim(x);
   name=scan(x{i},1,':');
   value=scan(x{i},-1,':');
   output;
 end;
keep id name value;
run;
proc transpose data=temp out=want(drop=_:);
by id ;
id name;
var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2019 13:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558619#M10134</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-14T13:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558623#M10136</link>
      <description>&lt;P&gt;If your data represents your actual problem, then do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID (var1-var3)($);
infile datalines dlm=',';
datalines;
1,x:1,y:1,z:5
2,z:3,y:7,x:5
3,x:9,y:4,z:4
4,y:1,z:1,x:5
5,y:2,x:15,z:9
;

data temp(drop=i var:);
   set have;
   array _{3} var1-var3;
   call sortc(of _[*]);
   do i=1 to dim(_);
      vname=scan(_[i], 1, ':');
      value=input(scan(_[i], 2, ':'), best8.);
      output;
   end;
run;

proc transpose data=temp out=want(drop=_name_);
   by id;
   id vname;
   var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2019 13:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558623#M10136</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-14T13:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558626#M10138</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/274084"&gt;@Sledgehamma&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your letter pattern is X, Y and Z in any &lt;STRONG&gt;unordered pattern, i&lt;/STRONG&gt;t's way too simple&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     (var1    var2    var3 ) ($);
cards;
1       x:1       y:1     z:5
2       z:3       y:7     x:5
3       x:9       y:4     z:4
4       y:1       z:1     x:5
5       y:2       x:15   z:9
;
run;

data want;
set have;
array t(*) var:;
array j(*)$ X Y Z;
call sortc(of var:);
do i=1 to dim(t);
t(i)=compress(t(i),,'kd');
j(i)=t(i);
end;
drop i var:;
run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2019 14:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558626#M10138</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-14T14:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558809#M10167</link>
      <description>Yes, there can be some missing values. I forgot to mention that.</description>
      <pubDate>Wed, 15 May 2019 06:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558809#M10167</guid>
      <dc:creator>Sledgehamma</dc:creator>
      <dc:date>2019-05-15T06:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating contextual variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558813#M10168</link>
      <description>&lt;P&gt;&lt;SPAN style="margin: 0px; color: #333333; font-family: '&amp;amp;quot',serif; font-size: 10.5pt;"&gt;Thank you all for your very fast and helpful solution! Seems to be a great community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="margin: 0px; color: #333333; font-family: '&amp;amp;quot',serif; font-size: 10.5pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="margin: 0px; color: #333333; font-family: '&amp;amp;quot',serif; font-size: 10.5pt;"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: You understood my Problem perfectly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I tried the solution you provided and it worked for my case.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="margin: 0px; color: #333333; font-family: '&amp;amp;quot',serif; font-size: 10.5pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="margin: 0px; color: #333333; font-family: '&amp;amp;quot',serif; font-size: 10.5pt;"&gt;Sadly, it showed that my data is even more badly structured than I thought. So for some "X" there is no mention of it. So instead of "X:5" there is only "5". However, since is actually not a 5 but a word, which I can clearly identify as variable x I think/hope I can work something out.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2019 06:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-contextual-variables/m-p/558813#M10168</guid>
      <dc:creator>Sledgehamma</dc:creator>
      <dc:date>2019-05-15T06:51:21Z</dc:date>
    </item>
  </channel>
</rss>

