<?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 Variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849733#M37154</link>
    <description>&lt;P&gt;Logically, I don't even understand what the statement is supposed to be doing, but it is a SAS syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if diff_tchol &amp;gt; 1 then ch_tchol &amp;gt; 1;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do something like this with an equal sign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if diff_tchol &amp;gt; 1 then ch_tchol = 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which avoids the SAS error, but it may not be what you want, and I am not any closer to understanding what you are trying to do logically. Could you explain what the logic is that you are trying to implement in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2022 20:40:13 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-12-14T20:40:13Z</dc:date>
    <item>
      <title>Creating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849732#M37153</link>
      <description>&lt;P&gt;Not sure what his error code is showing me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;error code&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;11   data fram_merge;
12   merge fram1_temp fram2_temp;
13   by subjid;
14   age = (vdate-bdate)/365.25;
15   diff_tchol = totchol2 - totchol;
16   if diff_tchol &amp;gt; 1 then ch_tchol &amp;gt; 1;
                            --------
                            180
17   else if diff_tchol &amp;lt; 1 then ch_tchol &amp;lt; 1;
                                 --------
                                 180
ERROR 180-322: Statement is not valid or it is used out of proper order.

18   if diff_tchol = 0 then chtchol = 0;
19   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FRAM_MERGE may be incomplete.  When this step was stopped there were 0
         observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sort data=fram1_temp; by subjid;
proc sort data=fram2_temp; by subjid; 
data fram_merge;
merge fram1_temp fram2_temp;
by subjid;
age = (vdate-bdate)/365.25;
diff_tchol = totchol2 - totchol;
run;
data fram_merge; 
if diff_tchol &amp;gt; 1 then ch_tchol &amp;gt; 1; 
else if diff_tchol &amp;lt; 1 then ch_tchol &amp;lt; 1;
if diff_tchol = 0 then ch_tchol = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is what I am trying to answer&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Create a variable called ch_tchol which equals –, 0, or + depending on whether diff_tchol is negative, zero, or positive in value respectively. &lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 20:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849732#M37153</guid>
      <dc:creator>MisterJenn</dc:creator>
      <dc:date>2022-12-14T20:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849733#M37154</link>
      <description>&lt;P&gt;Logically, I don't even understand what the statement is supposed to be doing, but it is a SAS syntax error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if diff_tchol &amp;gt; 1 then ch_tchol &amp;gt; 1;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do something like this with an equal sign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if diff_tchol &amp;gt; 1 then ch_tchol = 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which avoids the SAS error, but it may not be what you want, and I am not any closer to understanding what you are trying to do logically. Could you explain what the logic is that you are trying to implement in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 20:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849733#M37154</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-14T20:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849734#M37155</link>
      <description>Essentially this is what I am trying to do: Create a variable called ch_tchol which equals –, 0, or + depending on whether diff_tchol is negative, zero, or positive in value respectively.</description>
      <pubDate>Wed, 14 Dec 2022 20:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849734#M37155</guid>
      <dc:creator>MisterJenn</dc:creator>
      <dc:date>2022-12-14T20:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849735#M37156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/435394"&gt;@MisterJenn&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Essentially this is what I am trying to do: Create a variable called ch_tchol which equals –, 0, or + depending on whether diff_tchol is negative, zero, or positive in value respectively.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A numeric variable can't have a value of – or +, but it can have values of –1 or +1. So, here you go:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ch_tchol = sign(diff_tchol);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is different than what you tried to program, in which the cutoffs for diff_tchol was +1, but it is what you just said.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 20:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849735#M37156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-14T20:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849736#M37157</link>
      <description>&lt;P&gt;"-" and "+" are not numeric, but character values, so it seems your new variable needs to be of type character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if diff_tchol &amp;gt; 0
then ch_tchol = "+";
else if diff_tchol = 0
then ch_tchol = "0";
else ch_tchol = "-";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2022 21:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849736#M37157</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-14T21:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849750#M37166</link>
      <description>&lt;P&gt;Personally I wouldn't bother with creating an additional variable after you have the values of diff_tchol.&lt;/P&gt;
&lt;P&gt;I would use a custom format to show the values desired.&lt;/P&gt;
&lt;PRE&gt;proc format ;
value sign
low -&amp;lt;0 = '-'
0       = '0'
0 &amp;lt;- High='+'
;
run;

data example;
   input x;
datalines;
-4
.05
0
-.0001
10000000
;

proc print data=example;
   var x;
   format x sign.;
run;&lt;/PRE&gt;
&lt;P&gt;The groups created by a format will be honored by reporting or analysis procedures and most graph procedures.&lt;/P&gt;
&lt;P&gt;Also the -, 0, and + would sort in that order. Character values will generally be in a different order and quite often not the one you may want.&lt;/P&gt;
&lt;P&gt;Your code also missed any possibility that the difference might be between -1 and 0 or 0 and 1 .&lt;/P&gt;
&lt;P&gt;Another reason to consider a format is if you have multiple variables to do this sort of thing with one format can be applied to multiple variables and you do not have to create a separate character value for each. Might be something to consider if you have 50 values that you want to display as -,0,+.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 22:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creating-Variables/m-p/849750#M37166</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-14T22:44:22Z</dc:date>
    </item>
  </channel>
</rss>

