<?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: Splitting SAS dataset by multiple varying conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814750#M321599</link>
    <description>If the record count exceeds 500,000 for one SLOC, it would be submitted in two or more separate tasks. The receptive system requires the .xlsx file to be accepted as well. Thanks for the question...</description>
    <pubDate>Mon, 23 May 2022 18:02:55 GMT</pubDate>
    <dc:creator>arbnmedic33</dc:creator>
    <dc:date>2022-05-23T18:02:55Z</dc:date>
    <item>
      <title>Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814717#M321587</link>
      <description>&lt;P&gt;Greetings, first time poster, novice/intermediate user.&amp;nbsp; I have a SAS data set consisting of the following variables:&lt;/P&gt;&lt;P&gt;NIIN&amp;nbsp; &amp;nbsp;PLANT&amp;nbsp; &amp;nbsp;SLOC&amp;nbsp; &amp;nbsp;replen2&amp;nbsp; &amp;nbsp;COUNT&amp;nbsp; NUM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NIIN is the part number, all distinct entries&lt;/P&gt;&lt;P&gt;PLANT is the source, all the same (2001)&lt;/P&gt;&lt;P&gt;SLOC is the responsible entity for that NIIN (271 distinct entries)&lt;/P&gt;&lt;P&gt;COUNT is the numeric count of individual SLOC in the file (i.e. SLOC ABCD has 76,890 entries,&amp;nbsp; EFGH has 250, etc.)&lt;/P&gt;&lt;P&gt;NUM is the count from 1 to total observations in the file (1,922,802)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From this data, I need to create SAS data sets based on the following criteria:&lt;/P&gt;&lt;P&gt;Total NUM in the new datasets can't exceed 500,000 per data set&lt;/P&gt;&lt;P&gt;The SLOC entry can't be divided between the data sets (all ABCD must go into one data set...while not exceeding the 500,000 obs limit per set)&lt;/P&gt;&lt;P&gt;The issue is when I extract the first 500,000 obs, it falls right in the middle of one of the SLOCs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I configure SAS to create datasets based on the criteria mentioned above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The input file (&lt;SPAN&gt;NIIN&amp;nbsp; &amp;nbsp;PLANT&amp;nbsp; &amp;nbsp;SLOC&amp;nbsp; &amp;nbsp;replen2&amp;nbsp; &amp;nbsp;COUNT&amp;nbsp; NUM)&amp;nbsp;&lt;/SPAN&gt;will change each time I run the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 14:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814717#M321587</guid>
      <dc:creator>arbnmedic33</dc:creator>
      <dc:date>2022-05-23T14:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814720#M321588</link>
      <description>&lt;P&gt;This is really hard to understand. Can you create a small example, let's say 50 observations, that illustrates what you want? Show us the example data as SAS data step code, which you can type in yourself of by following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; (and not via other methods); and then show us the desired output.&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 15:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814720#M321588</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-23T15:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814721#M321589</link>
      <description>&lt;P&gt;Can you describe why exactly you need to create different data sets? And possibly why the 500,000 record limit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For use in SAS it is usually much easier to leave the data in one set and use either a BY statement to process groups of related records based on values of the variables or a WHERE statement to select specific records for a particular use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This becomes even more of an issue if, as you say, the records change constantly, i.e. each time you run the program.&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 15:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814721#M321589</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-23T15:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814722#M321590</link>
      <description>Apologies... Yes, give me a minute and I will put something together.</description>
      <pubDate>Mon, 23 May 2022 15:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814722#M321590</guid>
      <dc:creator>arbnmedic33</dc:creator>
      <dc:date>2022-05-23T15:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814729#M321592</link>
      <description>&lt;P&gt;So you only care that the SLOC entries are not split?&amp;nbsp; Doesn't matter if the values of the other variables are scatter across multiple files?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First get the number of observations per value of SLOC.&amp;nbsp; &amp;nbsp;(If that is not already one of the variables you have).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=HAVE;
  tables sloc / noprint out=counts ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now assign them into groups so that no group has more than 500,000.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data groups;
   if eof then call symputx('ngroups',group);
   set counts end=eof;
   retain group 0 running_count 0;
   if count + running_count &amp;gt; 500000 then do;
      group+1;
      running_count=0;
   end;
   running_count+count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can write a data step that will spit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's assume SLOC is a character variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code ;
data _null_;
   file code ;
   if _n_=1 then put "data group1-group&amp;amp;ngroups; set have;";
   set groups end=eof;
   by group;
   if first.group then put 'if sloc in (' @;
   put sloc :$quote. @;
   if last.group then put ') then output group' group ';' ;
   if eof then put 'run;';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can run that code and create the &amp;amp;Ngroups datasets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code/ source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2022 16:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814729#M321592</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-23T16:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814734#M321593</link>
      <description>&lt;P&gt;The data sets created from the original input file are to be exported to Excel and submitted into another gov system that is set up to receive only up to 500,000 records at a time (there are 1.9M observations in the input data) and the SLOC can't be split up between the new sets due to the requirements of that system.&amp;nbsp; The renaming of the variables is also required by that system.&amp;nbsp; Code is (so far):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;DATA A; INFILE 'C:\Users\ra\Documents\My SAS Files\SAS 9.4 Data\text\pdt_output_trimmed.txt' 
	TRUNCOVER FIRSTOBS = 2;
input	@1  NIIN $9.	
	@11 PLANT $4.	
	@16 SLOC $4.	
	@20 PDT $3.	
;
RUN;

DATA B; SET A; if PLANT = '2001';
	RENAME NIIN = niin PLANT = plant SLOC = sloc PDT = replen2;
	PROC SORT DATA = B; BY sloc NIIN;
RUN;

DATA C; SET B; BY sloc NIIN;
IF FIRST.sloc THEN COUNT = 1; ELSE COUNT = COUNT +1; RETAIN COUNT;
NUM+1;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The COUNT and NUM are my initial attempts to somehow identify the data for the subsets.&amp;nbsp; The splits for the new datasets must occur between the different SLOCs and must not exceed the 500,000 obs limit.&amp;nbsp; Problem is when I go to create the new data sets based on the number of observations, the splits occur in the middle of the SLOC, splitting that SLOC between two new SAS data sets.&amp;nbsp; Sorry of this seems convoluted, difficult to explain.&amp;nbsp; Just getting back into writing code after a few years away.&lt;/P&gt;&lt;P&gt;Example of the input data is as follows: (actual input .txt file has 1.9M obs)&amp;nbsp;and as mentioned before, this initial input data will change each month.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;NIIN	 	PLANT	SLOC	replen2	     COUNT	NUM	
013337632	2001	A011	25	       1	1
013569098	2001	A011	25	       2	2
014771660	2001	A011	25	       3	3
3014935859	2001	A011	25	       4	4
015004619	2001	A011	25	       5	5
015062715	2001	A011	25	       6	6
015064129	2001	A011	25	       7	7
015064131	2001	A011	25	       8	8
015064133	2001	A011	25	       9	9
015066873	2001	A011	25	       10	10
000000079	2001	A091	8	       1	11
000045256	2001	A091	8	       2	12
000050753	2001	A091	9	       3	13
000103030	2001	A091	8	       4	14
000115093	2001	A091	8	       5	15
000146763	2001	A091	8	       6	16
000179551	2001	A091	8	       7	17
000182296	2001	A091	8	       8	18
000187988	2001	A091	8	       9	19
000187989	2001	A091	8	       10	20
000599264	2001	A095	8	       1	21
000680509	2001	A095	8	       2	22
000686654	2001	A095	8	       3	23
000712075	2001	A095	8	       4	24
000712513	2001	A095	8	       5	25
000712515	2001	A095	8	       6	26
000811577	2001	A095	8	       7	27
000813381	2001	A095	9	       8	28
000847436	2001	A095	8	       9	29
000881251	2001	A095	9	      10	30
000888863	2001	A097	8	       1	31
000889167	2001	A097	8	       2        32
001000643	2001	A097	9	       3	33
001003095	2001	A097	8	       4	34
001005920	2001	A097	8	       5	35
001005937	2001	A097	8	       6	36
001045143	2001	A097	11	       7	37
001116255	2001	A097	9	       8	38
001217929	2001	A097	8	       9	39
001275322	2001	A097	8	      10	40
001278684	2001	A099	11	       1	41
001304235	2001	A099	8	       2	42
001319915	2001	A099	8	       3	43
001325317	2001	A099	8	       4	44
001349098	2001	A099	9	       5	45
001423036	2001	A099	8	       6	46
001433159	2001	A099	8	       7	47
001440091	2001	A099	22	       8	48
001503838	2001	A099	9              9	49
001513115	2001	A099	9	      10	50
001528353	2001	A123	8	       1	51
001648881	2001	A123	8	       2	52
001668567	2001	A123	9	       3	53
001670804	2001	A123	8	       4	54
001691934	2001	A123	9	       5	55
001691935	2001	A123	8	       6	56
001720031	2001	A132	8	       7	57
001727223	2001	A123	9	       8	58
001731881	2001	A123	8	       9	59
001744311	2001	A123	8	      10	60
001805038	2001	B111	8	       1	61
001827475	2001	B111	9	       2	62
001856345	2001	B111	9	       3	63
001879528	2001	B111	8	       4	64
001962017	2001	B111	8	       5	65
002000257	2001	B111	9	       6	66
002023639	2001	B111	10	       7	67
002024005	2001	B111	8	       8	68
002026692	2001	B111	8	       9	69
002043214	2001	B111	8	      10	70
002051711	2001	B555	13	       1	71
002052795	2001	B555	14             2	72
002212136	2001	B555	10	       3	73
002246657	2001	B555	8	       4	74
002256408	2001	B555	8	       5	75
002264828	2001	B555	8	       6	76
002266772	2001	B555	8	       7	77
002348422	2001	B555	8	       8	78
002403720	2001	B555	9	       9	79
002416659	2001	B555	8	      10	80&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 16:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814734#M321593</guid>
      <dc:creator>arbnmedic33</dc:creator>
      <dc:date>2022-05-23T16:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814742#M321595</link>
      <description>&lt;P&gt;So, what is your plan, or the Gov system plans, when a single SLOC exceeds 500,000 records?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that a maximum number of records is just one of the reasons Excel is a poor choice for interchanging data. And is the requirement actual an XLSX file or CSV? There seems to be considerable confusion in some parts of the world about CSV and "Excel file".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425950"&gt;@arbnmedic33&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The data sets created from the original input file are to be exported to Excel and submitted into another gov system that is set up to receive only up to 500,000 records at a time (there are 1.9M observations in the input data) and the SLOC can't be split up between the new sets due to the requirements of that system.&amp;nbsp; The renaming of the variables is also required by that system.&amp;nbsp; &lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 17:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814742#M321595</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-23T17:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814750#M321599</link>
      <description>If the record count exceeds 500,000 for one SLOC, it would be submitted in two or more separate tasks. The receptive system requires the .xlsx file to be accepted as well. Thanks for the question...</description>
      <pubDate>Mon, 23 May 2022 18:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814750#M321599</guid>
      <dc:creator>arbnmedic33</dc:creator>
      <dc:date>2022-05-23T18:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting SAS dataset by multiple varying conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814765#M321606</link>
      <description>Thanks Tom, appreciate the assistance...</description>
      <pubDate>Mon, 23 May 2022 18:46:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-SAS-dataset-by-multiple-varying-conditions/m-p/814765#M321606</guid>
      <dc:creator>arbnmedic33</dc:creator>
      <dc:date>2022-05-23T18:46:34Z</dc:date>
    </item>
  </channel>
</rss>

