<?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 proc sql: How to use the newly generated variable in this step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669387#M200805</link>
    <description>&lt;P&gt;i want to utilize the proc sql to compute the value. the studyid need to be replaced by 'cats(study,id)'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;usubjid = cats(the newly studyid,'-','subjid')&lt;/P&gt;&lt;P&gt;but the proc always use the The original&amp;nbsp; studyid in dm_raw.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the data dm_raw:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;studyid&lt;/TD&gt;&lt;TD&gt;subjid&lt;/TD&gt;&lt;TD&gt;study&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;001&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;002&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;003&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;004&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;the procedure:&lt;/P&gt;&lt;P&gt;proc sql；&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table dm as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; select cats(study,id) as studyid,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cats(studyid,'-',subjid) as usubjid&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; from dm_raw;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jul 2020 09:54:42 GMT</pubDate>
    <dc:creator>hyo_tree</dc:creator>
    <dc:date>2020-07-15T09:54:42Z</dc:date>
    <item>
      <title>proc sql: How to use the newly generated variable in this step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669387#M200805</link>
      <description>&lt;P&gt;i want to utilize the proc sql to compute the value. the studyid need to be replaced by 'cats(study,id)'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;usubjid = cats(the newly studyid,'-','subjid')&lt;/P&gt;&lt;P&gt;but the proc always use the The original&amp;nbsp; studyid in dm_raw.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the data dm_raw:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;studyid&lt;/TD&gt;&lt;TD&gt;subjid&lt;/TD&gt;&lt;TD&gt;study&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;001&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;002&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;003&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;250&lt;/TD&gt;&lt;TD&gt;004&lt;/TD&gt;&lt;TD&gt;20200515&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;the procedure:&lt;/P&gt;&lt;P&gt;proc sql；&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table dm as&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; select cats(study,id) as studyid,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cats(studyid,'-',subjid) as usubjid&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; from dm_raw;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 09:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669387#M200805</guid>
      <dc:creator>hyo_tree</dc:creator>
      <dc:date>2020-07-15T09:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: How to use the newly generated variable in this step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669400#M200810</link>
      <description>&lt;P&gt;please try below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql；
  create table dm as 
    select cats(study,id) as studyid,
               cats(cats(study,id),'-',subjid) as usubjid
    from dm_raw;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jul 2020 10:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669400#M200810</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-07-15T10:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: How to use the newly generated variable in this step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669405#M200811</link>
      <description>&lt;P&gt;Please do ALWAYS post your data in a data step with datalines, so we can be sure of variable types and other attributes, and the real contents of your dataset.&lt;/P&gt;
&lt;P&gt;In this case, "study" looks like a date, so it may be that the CATS() function does not yield the expected result.&lt;/P&gt;
&lt;P&gt;Also, ALWAYS use the proper subwindow for posting code ("little running man" right next to the one indicated, which is for logs):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg"&gt;&lt;img src="https://communities.sas.com/skins/images/E0BB18E7DAA53C21BC28740CEA0E38DA/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code as posted contained a "funny" semicolon, causing a syntax ERROR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to use a newly created variable in further operations, use the CALCULATED keyword:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table dm as 
  select
    cats(study,id) as studyid,
    cats(calculated studyid,'-',subjid) as usubjid
  from dm_raw
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jul 2020 10:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669405#M200811</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-15T10:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: How to use the newly generated variable in this step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669787#M200971</link>
      <description>Thanks for your clarification</description>
      <pubDate>Thu, 16 Jul 2020 02:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669787#M200971</guid>
      <dc:creator>hyo_tree</dc:creator>
      <dc:date>2020-07-16T02:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: How to use the newly generated variable in this step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669788#M200972</link>
      <description>thank you Jagadishkatam. i think the option 'caculated' is the better choice.,</description>
      <pubDate>Thu, 16 Jul 2020 02:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-How-to-use-the-newly-generated-variable-in-this-step/m-p/669788#M200972</guid>
      <dc:creator>hyo_tree</dc:creator>
      <dc:date>2020-07-16T02:48:01Z</dc:date>
    </item>
  </channel>
</rss>

