<?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: Variable conversion and operation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143244#M28656</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might provide some examples of whay your &amp;amp;cmryear variable actually looks like such as with %put.&lt;/P&gt;&lt;P&gt;Depeding on how/when you create it you might be better off creating a second variable: %let cmryearminus= %eval(&amp;amp;cmryear-1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And since many people asking about stuff in SQL sometimes take a long time to reveal they are attempting operations in another DBMS, is this actual SAS dataset you are using or is this passthrough or from another DBMS?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Jun 2014 14:39:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2014-06-16T14:39:50Z</dc:date>
    <item>
      <title>Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143242#M28654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following section of a proc sql.&amp;nbsp; The bold section below i am having trouble making it work.&amp;nbsp; I created a variable cmryear that contains a 4 digit year.&amp;nbsp; Depending on the date of the observation i may want to subtract one from the year for my cmrperiod variable.&amp;nbsp; Does anyone have a suggestion as to how i can do this.&amp;nbsp; I have tried put and input and just seem get errors when i do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I basicly want to subtract 1 from &amp;amp;cmryear variable for observations falling into the date range.&amp;nbsp; The problem is that It doesnt like the &amp;amp;cmr year because it is a character value so it has to be converted..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you all for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let cmr_period = "CN/KTZ 2016 CMR"&lt;/P&gt;&lt;P&gt;%let cmryear= %sysfunc(compress(&amp;amp;cmr_period ,"/",A));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put output of cmryear from log is&amp;nbsp; 2016&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;---other stuff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Case&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; when "&amp;amp;date_range_min"d &amp;lt;= datepart(transaction_date) &amp;lt;= "&amp;amp;date_range_max"d then catx(" ",mat.customer, "&amp;amp;cmryear", "CMR")&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; when intnx("year","&amp;amp;date_range_min"d,-1,"sameday") &amp;lt;= datepart(transaction_date) &amp;lt; "&amp;amp;date_range_Min"d then &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;catx(" ", &amp;amp;cmryear-1, "CMR")&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end as CMRPeriod,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;---other stuff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;log error&amp;nbsp; - ERROR: Expression using subtraction :smileyminus: requires numeric types.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 14:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143242#M28654</guid>
      <dc:creator>dsbihill</dc:creator>
      <dc:date>2014-06-16T14:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143243#M28655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yep, without seeing the errors am guessing, but copying and pasting the %let into the statement yields this:&lt;/P&gt;&lt;P&gt;then catx(" ",mat.customer, input(put(%sysfunc(compress(&amp;amp;cmr_period ,"/",A)),4.)-1,$4.), "CMR")&lt;/P&gt;&lt;P&gt;Which doesn't look right - e.g. what is the &amp;amp;cmr_period. Also, you have your inputs and put's mized up, input reads char into num, put outputs num as char.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Might I suggest you do it bit by bit. e.g:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input(strip(tranwrd(CMR_PERIOD,"/","")),best.) as MY_YEAR,&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;&amp;nbsp;&amp;nbsp; case&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; when ... then CALCULATED MY_YEAR&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;&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; else CALCULATED MY_YEAR - 1 end as ALTERED_YEAR,&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; catx(" ",MAT.CUSTOMER,strip(put(ALTERED_YEAR,best.)),"CMR") as FINAL_RESULT&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 14:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143243#M28655</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-16T14:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143244#M28656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might provide some examples of whay your &amp;amp;cmryear variable actually looks like such as with %put.&lt;/P&gt;&lt;P&gt;Depeding on how/when you create it you might be better off creating a second variable: %let cmryearminus= %eval(&amp;amp;cmryear-1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And since many people asking about stuff in SQL sometimes take a long time to reveal they are attempting operations in another DBMS, is this actual SAS dataset you are using or is this passthrough or from another DBMS?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 14:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143244#M28656</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-06-16T14:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143245#M28657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does the value of CMRYEAR actually look like YYYY?&lt;/P&gt;&lt;P&gt;If so then there you do not need to treat it as a character string in the SQL code.&amp;nbsp; You can pass an expression to the CATX() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: red; background: white;"&gt;case&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; when &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;"&amp;amp;date_range_min"d&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;lt;= datepart(transaction_date) &amp;lt;= &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;"&amp;amp;date_range_max"d&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; then catx(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;" "&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,mat.customer, &amp;amp;cmryear , &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"CMR"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; when intnx(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"year"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;"&amp;amp;date_range_min"d&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,-&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"sameday"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;) &amp;lt;= datepart(transaction_date) &amp;lt; &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;"&amp;amp;date_range_Min"d&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; then catx(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;" "&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,mat.customer, &amp;amp;cmryear - &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; , &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;"CMR"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; else &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;end as CMRPeriod&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 14:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143245#M28657</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-06-16T14:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143246#M28658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Updated my original question hopefully to clarify and answer the questions from both responses&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 15:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143246#M28658</guid>
      <dc:creator>dsbihill</dc:creator>
      <dc:date>2014-06-16T15:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143247#M28659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;wrap it in %eval,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%eval(&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt; &amp;amp;cmryear-1)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 15:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143247#M28659</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-06-16T15:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Variable conversion and operation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143248#M28660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Works perfectly thank you&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;Case &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt; when "&amp;amp;date_range_min"d &amp;lt;= datepart(transaction_date) &amp;lt;= "&amp;amp;date_range_max"d &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then catx(" ",mat.customer, "&amp;amp;cmryear", "CMR")&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt; when intnx("year","&amp;amp;date_range_min"d,-1,"sameday") &amp;lt;= datepart(transaction_date) &amp;lt; "&amp;amp;date_range_Min"d &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then catx(" ",mat.customer, %eval(&amp;amp;cmryear-1), "CMR")&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt; end as CMRPeriod,&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jun 2014 17:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-conversion-and-operation/m-p/143248#M28660</guid>
      <dc:creator>dsbihill</dc:creator>
      <dc:date>2014-06-16T17:27:38Z</dc:date>
    </item>
  </channel>
</rss>

