<?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 Dynamically generate tables from values in a field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672952#M202320</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I have a master table that I make several other tables from based on user_name.&lt;/P&gt;&lt;P&gt;Ex:&lt;BR /&gt;Master table&lt;BR /&gt;Table A columns: Acct, Date, Status, User_Name&lt;BR /&gt;&lt;BR /&gt;then I inefficiently do something like:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table John&lt;/P&gt;&lt;P&gt;as select * from work.A&amp;nbsp; where name = 'John'&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table Jane&lt;/P&gt;&lt;P&gt;as select * from work.A where name = 'Jane'&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then later I export all of these, sticking to the same convention of writing several export statements all from my user_name work tables. It sucks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I only had a few users, and they never changed, I wouldn't care. But I have around 10 that vary based on hiring and firing, and i have this process automated, except I have to manually go in and edit users when and if they change.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm fairly new to programming, but have done similar things with macros/python/vba before. I just want to stick in SAS for this particular process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm just running into a wall in my head because the user_names aren't knowable like months or days or something, so it would need to be a select distinct user_name, but I'm really at a loss.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jul 2020 19:03:28 GMT</pubDate>
    <dc:creator>hporter</dc:creator>
    <dc:date>2020-07-28T19:03:28Z</dc:date>
    <item>
      <title>Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672952#M202320</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I have a master table that I make several other tables from based on user_name.&lt;/P&gt;&lt;P&gt;Ex:&lt;BR /&gt;Master table&lt;BR /&gt;Table A columns: Acct, Date, Status, User_Name&lt;BR /&gt;&lt;BR /&gt;then I inefficiently do something like:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table John&lt;/P&gt;&lt;P&gt;as select * from work.A&amp;nbsp; where name = 'John'&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table Jane&lt;/P&gt;&lt;P&gt;as select * from work.A where name = 'Jane'&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then later I export all of these, sticking to the same convention of writing several export statements all from my user_name work tables. It sucks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I only had a few users, and they never changed, I wouldn't care. But I have around 10 that vary based on hiring and firing, and i have this process automated, except I have to manually go in and edit users when and if they change.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm fairly new to programming, but have done similar things with macros/python/vba before. I just want to stick in SAS for this particular process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm just running into a wall in my head because the user_names aren't knowable like months or days or something, so it would need to be a select distinct user_name, but I'm really at a loss.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 19:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672952#M202320</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2020-07-28T19:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672953#M202321</link>
      <description>&lt;P&gt;If your names can all be used as valid SAS names, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table names as
  select distinct name
  from a
;
quit;

data _null_;
call execute('data');
do until (eof1);
  set names end=eof1;
  call execute(" " !! name);
end;
call execute('; select(name);');
do until (eof2);
  set names end=eof2;
  call execute('when ("' !! strip(name) !! '") output ' !! strip(name) !! ';');
end;
call execute('end; run;');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 21:48:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672953#M202321</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-28T21:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672960#M202324</link>
      <description>&lt;P&gt;When you have something like this :&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table John
as select * from work.A  where name = 'John'
;quit;
 
proc sql;
create table Jane
as select * from work.A where name = 'Jane'
;quit;
&lt;/PRE&gt;
&lt;P&gt;Coupled with "export all of these, sticking to the same convention of writing several export statements all from my user_name work table" very likely means that a report from Work.a could be made using some sort of BY group processing based on the values of Name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not show any of the relationship between the contents of Work.A and the only variable, Name, does not appear in your Master Table description, so it is very hard to tell what you are attempting to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do &lt;STRONG&gt;you&lt;/STRONG&gt; as the use know that a "specific name" is needed?&lt;/P&gt;
&lt;P&gt;Or are you actually meaning "I need to do this for the names that do appear in the data but I don't know which ones will be there."? &amp;lt;= That is exactly what BY group processing does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: Provide 1) a small example of your "Master Table", 2) Some example data of your Work.A and 3) what the final report would look like. If any summaries or such need to be done as part of the report provide the rules.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 19:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672960#M202324</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-28T19:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672993#M202345</link>
      <description>&lt;P&gt;Oh, wait, you do these for&amp;nbsp;&lt;EM&gt;export&lt;/EM&gt;, not for sending/distributing the datasets themselves? You can do that much easier with BY group processing directly from the dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 21:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/672993#M202345</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-28T21:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673010#M202362</link>
      <description>&lt;P&gt;Your goal seems to be wanting to export a discrete file per employee.&amp;nbsp; Using the code below modified to your data you can create an Excel file with a separate worksheet for each person&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FILENAME out '~/img/cars.xlsx';
proc sort data=sashelp.cars out=cars;
by origin;
run;
options nobyline;
ods listing close;
ods excel file=out  options(sheet_name='#byval1');
proc print data=cars;
by origin;
run;
ods excel close;
ods listing;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2020 00:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673010#M202362</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-07-29T00:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673210#M202471</link>
      <description>My apologies, yeah I should have said the end result.&lt;BR /&gt;&lt;BR /&gt;I need separate files to be exported for each individual user.&lt;BR /&gt;&lt;BR /&gt;So I don't actually need work tables of the users, I'm realizing that now, I can get away with just having one parent table, but then in the export I need to export 'by user_name.'&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Jul 2020 16:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673210#M202471</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2020-07-29T16:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673220#M202475</link>
      <description>So I'm really only concerned with having several files as my end result, all with the name of the users that appear in my parent table.&lt;BR /&gt;&lt;BR /&gt;I had googled before how to do a 'proc export by (field_name)' or something to no avail, although it makes sense that it would exist.&lt;BR /&gt;&lt;BR /&gt;The data is all proprietary, but the parent table would be as such:&lt;BR /&gt;Column&lt;BR /&gt;Row Acct Date Status User Name&lt;BR /&gt;123 7/01/2020 ACT JOHN&lt;BR /&gt;876 7/03/2020 ACT JOHN&lt;BR /&gt;456 7/15/2020 ACT JANE&lt;BR /&gt;987 6/26/2020 NA MIKE&lt;BR /&gt;113 1/07/2018 ACT JANE&lt;BR /&gt;&lt;BR /&gt;I need to export individual files for each user in the user_name field, so that I'd have a file for John, with all the accounts/data associated with him, a file for Mike, and all the accounts associated with him, a file for Jane, with all the accounts associated with her, etc.</description>
      <pubDate>Wed, 29 Jul 2020 17:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673220#M202475</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2020-07-29T17:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673223#M202477</link>
      <description>Initially I was hoping to have individual files, but this is actually fantastic and might work depending on whether the client accepts it, regardless I learned something.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot!</description>
      <pubDate>Wed, 29 Jul 2020 17:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673223#M202477</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2020-07-29T17:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673228#M202481</link>
      <description>&lt;P&gt;That's great, if you like the solution could you mark it as accepted please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you were not specific in the export file format, I used Excel since from my experience that is the most common format, keeping all the data in one file.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 17:19:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673228#M202481</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-07-29T17:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically generate tables from values in a field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673229#M202482</link>
      <description>Xlsx works great, and yes I can do that.&lt;BR /&gt;&lt;BR /&gt;Thanks for your time</description>
      <pubDate>Wed, 29 Jul 2020 17:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-generate-tables-from-values-in-a-field/m-p/673229#M202482</guid>
      <dc:creator>hporter</dc:creator>
      <dc:date>2020-07-29T17:28:56Z</dc:date>
    </item>
  </channel>
</rss>

