<?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: Data step into proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591717#M169568</link>
    <description>&lt;P&gt;I guess the problem is of keeping all original variables but changing the format of just two columns. Can be done with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table dis_entity_id as
	select * from &amp;amp;library..&amp;amp;input_table
	order by ENTITY_ID, REPORTING;
alter table dis_entity_id 
	modify 
		ENTITY_ID CHARACTER format=$ENTITY.,
		REPORTING CHARACTER format=$50.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Sep 2019 21:40:33 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-09-25T21:40:33Z</dc:date>
    <item>
      <title>Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591475#M169428</link>
      <description>&lt;P&gt;Is there a way that we can convert the below data steps into one proc SQL step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dis_entity_id ;
  set &amp;amp;library..&amp;amp;input_table ;
  format ENTITY_ID $ENTITY. REPORTING $50.;
  keep ENTITY_ID REPORTING;
run;

proc sort data=dis_entity_id nodupkey;
  by ENTITY_ID REPORTING;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2019 12:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591475#M169428</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-25T12:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591476#M169429</link>
      <description>&lt;P&gt;I can't see your data so needless to say, this code is untested&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table dis_entity_id as
    select distinct ENTITY_ID format=$ENTITY.,
           REPORTING format=$50.
    from &amp;amp;library..&amp;amp;input_table
    order by ENTITY_ID, REPORTING;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2019 12:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591476#M169429</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-25T12:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591717#M169568</link>
      <description>&lt;P&gt;I guess the problem is of keeping all original variables but changing the format of just two columns. Can be done with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table dis_entity_id as
	select * from &amp;amp;library..&amp;amp;input_table
	order by ENTITY_ID, REPORTING;
alter table dis_entity_id 
	modify 
		ENTITY_ID CHARACTER format=$ENTITY.,
		REPORTING CHARACTER format=$50.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 21:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591717#M169568</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-25T21:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591783#M169590</link>
      <description>&lt;P&gt;Data steps which I mentioned in the intial post will create a variable(s) like ENTITY_ID&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; REPORTING...&amp;nbsp;in case if it is not available in source dataset. However your code has ended with error as below. I forgot to mention this point in my post. How to tweak your code now to produce the desired result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         data test;
27         input REPORTING $;
28         datalines;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      
30         ;

31         run;
32         
33         proc sql;
34             create table dis_entity_id as
35             select distinct ENTITY_ID format=$ENTITY.,
36                    REPORTING format=$50.
37             from test
38             order by ENTITY_ID, REPORTING;
ERROR: The following columns were not found in the contributing tables: ENTITY_ID.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
39         quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 06:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591783#M169590</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-26T06:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591784#M169591</link>
      <description>&lt;P&gt;Data steps which I mentioned in the intial post will create a variable(s) like ENTITY_ID&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; REPORTING...&amp;nbsp;in case if it is not available in source dataset. However your code has ended with error as below. I forgot to mention this point in my post. How to tweak your code now to produce the desired result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         proc sql;
27         create table dis_entity_id as
28         	select * from test
29         	order by ENTITY_ID, REPORTING;
ERROR: The following columns were not found in the contributing tables: ENTITY_ID.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
30         alter table dis_entity_id
31         	modify
32         		ENTITY_ID CHARACTER format=$ENTITY.,
33         		REPORTING CHARACTER format=$50.;
NOTE: Statement not executed due to NOEXEC option.
34         quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Sep 2019 06:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591784#M169591</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-26T06:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591888#M169652</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Data steps which I mentioned in the intial post will create a variable(s) like ENTITY_ID&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; REPORTING...&amp;nbsp;in case if it is not available in source dataset. However your code has ended with error as below. I forgot to mention this point in my post. How to tweak your code now to produce the desired result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;26         proc sql;
27         create table dis_entity_id as
28         	select * from test
29         	order by ENTITY_ID, REPORTING;
ERROR: The following columns were not found in the contributing tables: ENTITY_ID.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
30         alter table dis_entity_id
31         	modify
32         		ENTITY_ID CHARACTER format=$ENTITY.,
33         		REPORTING CHARACTER format=$50.;
NOTE: Statement not executed due to NOEXEC option.
34         quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you change the FROM data set name to one you actually have with the appropriate data?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 15:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591888#M169652</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-26T15:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591893#M169655</link>
      <description>Yes, I did changed the FROM dataset to have one variable REPORTING.&lt;BR /&gt;&lt;BR /&gt;could you please help me to either combine your two data step into one step&lt;BR /&gt;either using data step or proc sql?&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Sep 2019 15:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591893#M169655</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-26T15:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Data step into proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591904#M169659</link>
      <description>&lt;P&gt;You didn't explain the PURPOSE of the data step.&lt;/P&gt;
&lt;P&gt;From your later comments it sounds like the purpose is to force the creation of those two variables.&amp;nbsp; Not sure why you would want to attach the $50. format to the second variable, especially if it could already exist and have a different length than 50 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's assume that the purpose is to create REPORTING as a character variable of length 50.&amp;nbsp; You don't show how you want ENTITY_ID created (or the definition of the $ENTITY. format) so let's just assume it should be a character variable of length 3 and use the $CHAR3. format as place holder for the $ENTITY. format in the code.&amp;nbsp; Here is code using OUTER UNION CORRESPONDING and pulling the NAME variable from SASHELP.CLASS to give SQL a source for the definition of the potential extra columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table dis_entity_id as 
select * from &amp;amp;library..&amp;amp;input_table
outer union corresponding 
select name as entity_id length=3 format=$char3.
     , name as reporting length=50 
from sashelp.class(obs=0)
order by entity_id, reporting
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that is is much harder to implement the NODUPKEY functionality of PROC SORT in PROC SQL.&amp;nbsp; Unless the table actually only has those two variables.&amp;nbsp; In which case the query could then be something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table dis_entity_id as 
select distinct
   entity_id format=$char3.
 , reporting 
from
(
select * from &amp;amp;library..&amp;amp;input_table
outer union corresponding 
select name as entity_id length=3 
     , name as reporting length=50 
from sashelp.class(obs=0)
)
order by entity_id, reporting
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 15:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-into-proc-sql/m-p/591904#M169659</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-26T15:56:06Z</dc:date>
    </item>
  </channel>
</rss>

