<?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: How to macro for all files in one folder regarding distinc value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728382#M226643</link>
    <description>&lt;P&gt;My bad. Change the SQL to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx(".",libname,memname) !! "(keep=curcdd loc)" into :dsnames separated by " "
from dictionary.tables
where libname = "TESTS";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Forgot to add the library to the dataset identifier.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Mar 2021 09:58:49 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-23T09:58:49Z</dc:date>
    <item>
      <title>How to macro for all files in one folder regarding distinc value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728327#M226624</link>
      <description>&lt;P&gt;Hi all SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Today I want to do find how many distinct value of currency (&lt;STRONG&gt;curcdd&lt;/STRONG&gt;)( a character variable)of a country. Because the dataset is large so I split them into many small files in one folder as in the picture below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Phil_NZ_0-1616461163164.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56283i7A96CB4AD9B8052C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Phil_NZ_0-1616461163164.png" alt="Phil_NZ_0-1616461163164.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;For example, my code successfully run for one file to retrieve the distinct currency for Romania (&lt;STRONG&gt;LOC='ROU'&lt;/STRONG&gt;) in file &lt;STRONG&gt;keepvar_1999_2001&lt;/STRONG&gt; is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname tests 'E:\Harv 27th_Feb_2021\data_cut';

proc sql;
   create table _1999_2001 as
   select distinct curcdd
   from tests.keepvar_1999_2001
   where LOC='ROU';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am wondering how to code to get the distinct value of &lt;STRONG&gt;curcdd&lt;/STRONG&gt; for all files in this folder for Romania (LOC='ROU').&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought it would relate to the code below but I do not know how to merge them together:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=tests._ALL_ out=contents;
run;
proc sql noprint;
	select distinct catx('.',libname,memname)
	into :dslist separated by ' '
	from contents
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One further question is how to do the same things (distinct value of currency ) for LOC in array ('AUS','AUT','BEL','CAN','CYP','DNK','FIN','FRA','DEU',&lt;BR /&gt;'GRC','HKG','IRL','ISR','ITA','JPN','LUX','NLD','NZL','NOR','PRT',&lt;BR /&gt;'SGP','KOR','ESP','SWE','CHE','TWN','GBR','USA','ARG','BRA','CHL',&lt;BR /&gt;'CHN','COL','HRV','CZE','EGY','EST','HUN','IND','IDN','KEN','LTU',&lt;BR /&gt;'MYS','MEX','MAR','PAK','PER','PHL','POL','ROU','SVN','ZAF','LKA',&lt;BR /&gt;'THA','TUR','VEN','LVA','SVK','BGR') for all files in this folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 01:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728327#M226624</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-23T01:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to macro for all files in one folder regarding distinc value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728348#M226628</link>
      <description>&lt;P&gt;Define "large".&lt;/P&gt;
&lt;P&gt;Your question illustrates why it is a bad idea to split datasets, it only causes more work.&lt;/P&gt;
&lt;P&gt;Define a data step view that concatenates the datasets.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 05:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728348#M226628</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-23T05:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to macro for all files in one folder regarding distinc value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728349#M226629</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestion. Originally, this file is 2.8TB in total, so the person who first deal with this file split it into many small files for uploading and downloading. The thing is, because the hard disk in our school is just around 120GB, so we need to do things on that way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The way he did is: for example, companies has daily observations from 1/1/1999 to 31/02/2021, so the file keep_var_1999_2001 will contain daily observation of all firms, file keep_var_2020_2021 will contain daily observation of all firms in 2020 and 2021.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The way I concatenate the dataset is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc contents data=tests._ALL_ out=contents;
run;

proc sql ;
create table variables as 
  select upcase(name) as name
          , sum(type=1) as n_num
         ,  sum(type=2) as n_char
         , max(length) as max_length
 from contents
  group by 1
;
quit;



proc sql noprint;
	select distinct catx('.',libname,memname)
	into :dslist separated by ' '
	from contents
	;
quit;

data ex_non_tradi / view=ex_non_tradi;
/*ex_non_tradi is the concatenated file*/
	length CIK $40 CSHOC 8 DATADATE 8 DOLLAR_VOL 8 EX_RATE 8
		   GVIIDKEY $200 ISIN $48 LOC $12 LOG_RAW_RETURN 8 PRCCD 8
		   PRCCD_ABS_ 8 PRCHD 8 PRCLD 8 RAW_RETURN_ABS 8 SEDOL $28 
		   AJEXDI 8 LAGAJEXDI 8 LAGTRFD 8 TRFD 8 CUSIP $36
	;
	set &amp;amp;dslist.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please let me know if my explanation is still ambiguous.&lt;/P&gt;
&lt;P&gt;Warmest regards.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 05:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728349#M226629</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-23T05:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to macro for all files in one folder regarding distinc value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728359#M226633</link>
      <description>&lt;P&gt;If you want a table containing the distinct currency/location combinations for all datasets in your library, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select memname !! "(keep=curcdd loc)" into :dsnames separated by " "
from dictionary.tables
where libname = "TESTS";
quit;

data all_ds / view=all_ds;
set &amp;amp;dsnames.;
run;

data _null_;
set all_ds end=done;
if _n_ = 1
then do;
  declare hash out ();
  out.definekey("curcdd","loc");
  out.definedata("curcdd","loc");
  out.definedone();
end;
if out.find() ne 0 then rc = out.add();
if done then rc = out.output(dataset:"want");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first step retrieves all datasets in the library, the second creates the data step view, and the third builds a hash object with all distinct combinations and writes them out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;EM&gt;Edit: added a closing bracket for the keep= option&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 09:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728359#M226633</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-23T09:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to macro for all files in one folder regarding distinc value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728379#M226641</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your help.&lt;/P&gt;
&lt;P&gt;I do not know what happened when I tried to run the second set of code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_ds / view=all_ds;
set &amp;amp;dsnames.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is the log:&lt;/P&gt;
&lt;PRE&gt;34         data all_ds / view=all_ds;
35         set &amp;amp;dsnames.;
ERROR: File WORK.KEEPVAR_1999_2001.DATA does not exist.
ERROR: File WORK.KEEPVAR_1999_2010_US.DATA does not exist.
ERROR: File WORK.KEEPVAR_2002_2004.DATA does not exist.
ERROR: File WORK.KEEPVAR_2005_2007.DATA does not exist.
ERROR: File WORK.KEEPVAR_2008_2010.DATA does not exist.
ERROR: File WORK.KEEPVAR_2011_2013.DATA does not exist.
ERROR: File WORK.KEEPVAR_2011_2020_US.DATA does not exist.
ERROR: File WORK.KEEPVAR_2014_2016.DATA does not exist.
ERROR: File WORK.KEEPVAR_2017_2019.DATA does not exist.
ERROR: File WORK.KEEPVAR_2020_2021.DATA does not exist.&lt;/PRE&gt;
&lt;P&gt;Could you please let me know how to sort it out? It is quite strange to me because these datasets totally exist in this folder.&lt;/P&gt;
&lt;P&gt;Warm regards.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 09:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728379#M226641</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-03-23T09:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to macro for all files in one folder regarding distinc value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728382#M226643</link>
      <description>&lt;P&gt;My bad. Change the SQL to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx(".",libname,memname) !! "(keep=curcdd loc)" into :dsnames separated by " "
from dictionary.tables
where libname = "TESTS";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Forgot to add the library to the dataset identifier.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 09:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-macro-for-all-files-in-one-folder-regarding-distinc-value/m-p/728382#M226643</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-23T09:58:49Z</dc:date>
    </item>
  </channel>
</rss>

