<?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: Select Columns From Values of other sql statement in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867164#M42657</link>
    <description>&lt;P&gt;What is your GETNAMES setting on PROC IMPORT? Try GETNAMES = YES if you were using NO.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2023 03:27:27 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-03-30T03:27:27Z</dc:date>
    <item>
      <title>Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867157#M42651</link>
      <description>&lt;P&gt;My requirement is to to get only select columns which are the values of sql statement&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create table Sorting_Initial_1 as
select *
rom SASHELP.VCOLUMN
where libname = 'WORK'
and memname='DATA_SAM';
quit;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;The above code will give all column names from data_sam table&lt;BR /&gt;i am now writing the below code&lt;/P&gt;&lt;PRE&gt;proc sql;
create table sorting_initial_2 as
select name
from Sorting_Initial_1
where name like'goal%'or name='client';
quit;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Whose output is a column with all column names&lt;BR /&gt;I want to use the values of name in select statement to bring only those columns&lt;BR /&gt;The code i am using is wrong but in the select statement i want to bring the values of name from above query.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table sorting_initial_3 as
select sorting_initial_2.*
from WORK.DATA_SAM;
quit;&lt;/PRE&gt;&lt;P&gt;My overall requirement is to select columns that start with same prefix&lt;BR /&gt;eg : in below picture i want only columns client and all columns that have goal&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 680px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82180iC437EFD4333CC6EC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 01:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867157#M42651</guid>
      <dc:creator>sai_12</dc:creator>
      <dc:date>2023-03-30T01:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867159#M42652</link>
      <description>&lt;P&gt;Hi everyone i was able to solve this&lt;/P&gt;&lt;P&gt;using&lt;/P&gt;&lt;PRE&gt;proc sql;
  create table Sorting_Initial_1 as
  select *
  from SASHELP.VCOLUMN 
  where libname = 'WORK' and memname='DATA_SAM';

  select name into :names separated by ','
  from Sorting_Initial_1
  where name like 'goal%' or name='client';
 
  create table sorting_initial_3 as
  select &amp;amp;names.
  from WORK.DATA_SAM;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Mar 2023 02:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867159#M42652</guid>
      <dc:creator>sai_12</dc:creator>
      <dc:date>2023-03-30T02:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867160#M42653</link>
      <description>&lt;P&gt;Just a addon question:&lt;/P&gt;&lt;P&gt;At the moment i used import data from file-&amp;gt; importdata to bring data into work lib&lt;/P&gt;&lt;P&gt;I believe that is the reason why created suffix eg: goal,goal_0001,goal_0002 etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when i use proc import it gives var1,var2 for duplicated columns can any one let me know how to stop this and give me suffix eg: goal_0001 instead of var1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 02:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867160#M42653</guid>
      <dc:creator>sai_12</dc:creator>
      <dc:date>2023-03-30T02:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867161#M42654</link>
      <description>&lt;P&gt;If you would prefer a MACRO approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Query_Columns ( Library = 
                      ,table = 
                      ,Column =
                      ,Column_Start = );

Proc sql noprint;
select name
into :Name_List separated by ','
from SASHELP.VCOLUMN
where libname = upcase("&amp;amp;Library")
and memname = upcase("&amp;amp;table")
and (upcase(name) = upcase("&amp;amp;Column")
     or upcase(name) like upcase("&amp;amp;Column_Start.%")
    )
;
create table &amp;amp;table as
select  &amp;amp;Name_List
from &amp;amp;Library..&amp;amp;table 
quit;

%mend;

%Query_Columns ( Library = sashelp
                ,table = class
                ,Column = name
                ,Column_Start = wei);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Mar 2023 02:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867161#M42654</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-03-30T02:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867162#M42655</link>
      <description>Just a addon question:&lt;BR /&gt;&lt;BR /&gt;At the moment i used import data from file-&amp;gt; importdata to bring data into work lib&lt;BR /&gt;&lt;BR /&gt;I believe that is the reason why created suffix eg: goal,goal_0001,goal_0002 etc&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But when i use proc import it gives var1,var2 for duplicated columns can any one let me know how to stop this and give me suffix eg: goal_0001 instead of var1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;thank you</description>
      <pubDate>Thu, 30 Mar 2023 03:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867162#M42655</guid>
      <dc:creator>sai_12</dc:creator>
      <dc:date>2023-03-30T03:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867164#M42657</link>
      <description>&lt;P&gt;What is your GETNAMES setting on PROC IMPORT? Try GETNAMES = YES if you were using NO.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 03:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867164#M42657</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-03-30T03:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867171#M42659</link>
      <description>&lt;P&gt;yes i tried get names=true;&lt;/P&gt;&lt;P&gt;for attached csv file i am using this code&lt;/P&gt;&lt;PRE&gt;proc import datafile = "\\something\data_Sam.csv"
  out = datasample
  dbms=csv
  replace;
  getnames=yes;
run;&lt;/PRE&gt;&lt;P&gt;With the above code i get var4 instead i want goal_suffix&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 760px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82183iB85711BB3152699F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sai_12_0-1680148708002.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82184iE9C79117A48518A4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sai_12_0-1680148708002.png" alt="sai_12_0-1680148708002.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 03:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867171#M42659</guid>
      <dc:creator>sai_12</dc:creator>
      <dc:date>2023-03-30T03:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select Columns From Values of other sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867177#M42660</link>
      <description>&lt;P&gt;Names of columns must be unique, so if sas encounters a name a second time, it does not just add a number to that name, it starts with var1. To read a text file, i would write a data step.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 05:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-Columns-From-Values-of-other-sql-statement/m-p/867177#M42660</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-03-30T05:40:34Z</dc:date>
    </item>
  </channel>
</rss>

