<?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: SAS code help needed: How to create separate data files based on the Site ID? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958755#M374165</link>
    <description>&lt;P&gt;If you have list of unique SITE values in a dataset then you can generate a SPLIT number easily with a DO loop around a SET statement.&amp;nbsp; So if you have dataset name SITES with variable SITE in the order you want you can use this data step to make a dataset with the SPLIT value for each SITE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data site_split;
  split+1;
  do i=1 to 13 ;
    set site;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that dataset to generate your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_ ;
  set site_split end=eof;
  by split;
  file code lrecl=80 ;
  if _n_=1 then put 'data ' @;
  if first.split then put 'plot_iq_hist_split' split @;
  if eof then put ';' / 'set plot_iq_hist;'  ;
run;
data _null_;
  set site_split end=eof;
  by split;
  file code mod lrecl=80 ;
  if first.split then do;
    if _n_&amp;gt;1 then put 'else ' @;
    put 'if site in (' @;
  end;
  put site :$quote. @;
  if last.split then put ') then output plot_iq_hist_split' split ';' ;
  if eof then put 'run;' ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 08 Feb 2025 18:44:10 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-08T18:44:10Z</dc:date>
    <item>
      <title>SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958754#M374164</link>
      <description>&lt;P&gt;I need to create the weekly report including the histograms for showing all the individual site info.&amp;nbsp; Each week, new sites are added and I have to manually modify the code.&amp;nbsp; I am wondering whether there is a way to program to create the data files including 13 sites in each histogram ordered by the Site ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the current code:&lt;/P&gt;
&lt;P&gt;/* Create three datasets split by Site - 13 sites per graph*/&lt;BR /&gt;data plot_iq_hist_split1 plot_iq_hist_split2 plot_iq_hist_split3 plot_iq_hist_split4;&lt;BR /&gt;set plot_iq_hist;&lt;BR /&gt;if site IN ('001', '002', '004', '005', '008','013', '018','020', '021', '022', '025', '026','027') then output plot_iq_hist_split1;&lt;BR /&gt;else if site IN ('029', '030' '032', '033','035','038', '040', '041', '042', '043', '044','046', '051') &lt;BR /&gt;then output plot_iq_hist_split2;&lt;BR /&gt;else if site IN ('052', '054', '056', '057', '059', '061', '064', '065', '066', '068', '072', '074', '080') then output plot_iq_hist_split3;&lt;BR /&gt;else output plot_iq_hist_split4;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2025 18:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958754#M374164</guid>
      <dc:creator>J_Park</dc:creator>
      <dc:date>2025-02-08T18:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958755#M374165</link>
      <description>&lt;P&gt;If you have list of unique SITE values in a dataset then you can generate a SPLIT number easily with a DO loop around a SET statement.&amp;nbsp; So if you have dataset name SITES with variable SITE in the order you want you can use this data step to make a dataset with the SPLIT value for each SITE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data site_split;
  split+1;
  do i=1 to 13 ;
    set site;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use that dataset to generate your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_ ;
  set site_split end=eof;
  by split;
  file code lrecl=80 ;
  if _n_=1 then put 'data ' @;
  if first.split then put 'plot_iq_hist_split' split @;
  if eof then put ';' / 'set plot_iq_hist;'  ;
run;
data _null_;
  set site_split end=eof;
  by split;
  file code mod lrecl=80 ;
  if first.split then do;
    if _n_&amp;gt;1 then put 'else ' @;
    put 'if site in (' @;
  end;
  put site :$quote. @;
  if last.split then put ') then output plot_iq_hist_split' split ';' ;
  if eof then put 'run;' ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2025 18:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958755#M374165</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-08T18:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958757#M374167</link>
      <description>&lt;P&gt;Is it really necessary to split the data into four different datasets?&amp;nbsp; Why not just make a variable named Split, with values 1-4?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't provide sample data, but it could be done like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set plot_iq_hist ;
  by site ;
  if first.site then do ;
    sitecounter++1 ;
    if sitecounter=1 then split++1 ;
  end ;
  if last.site and sitecounter=13 then sitecounter=0 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2025 18:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958757#M374167</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-02-08T18:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958758#M374168</link>
      <description>Agree - easier to keep this all in one dataset and split them into separate panels of 13 each in SGPANEL.</description>
      <pubDate>Sat, 08 Feb 2025 18:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958758#M374168</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-02-08T18:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958759#M374169</link>
      <description>&lt;P&gt;The one I posted before made no sense whatsoever.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_histo_data(indata=, insheet=);

	proc import out=plot_iq_hist dbms=xlsx replace
		datafile="&amp;amp;indata";
	sheet="&amp;amp;insheet";
	run;
	
	proc sql noprint;
	select ceil(count(distinct site)/13) into :ndatasets trimmed from plot_iq_hist;
	quit;
	
	proc sort data=plot_iq_hist; by site; run;
	
	DATA 
	%do i=1 %to &amp;amp;ndatasets;
		plot_iq_hist_split&amp;amp;i
	%end;
		;
	set plot_iq_hist;
	by site;
	sitenum+first.site;
	%do i=1 %to &amp;amp;ndatasets;
		if ceil(sitenum/13)=&amp;amp;i then output plot_iq_hist_split&amp;amp;i;
	%end;
	run;
	
%mend; *split_histo_data();

%split_histo_data(indata=%str(/path/to/data/exceldata.xlsx), insheet=histodata);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2025 19:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958759#M374169</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-02-08T19:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958762#M374171</link>
      <description>Since I need to provide N for each bar in the histogram per site, it gets crowded with many sites, so i had to split the data for multiple graphs.  I treid SGPanel but it shows each site separately.  I don't know how to make 13 site per panel.&lt;BR /&gt;</description>
      <pubDate>Sat, 08 Feb 2025 20:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958762#M374171</guid>
      <dc:creator>J_Park</dc:creator>
      <dc:date>2025-02-08T20:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958763#M374172</link>
      <description>Thank you for the solution!   This code worked beautifully!   I didn't have to create separate data but used the new variable called "split" and created separate graphs.  Thank you so much!!!</description>
      <pubDate>Sat, 08 Feb 2025 20:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958763#M374172</guid>
      <dc:creator>J_Park</dc:creator>
      <dc:date>2025-02-08T20:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code help needed: How to create separate data files based on the Site ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958764#M374173</link>
      <description>&lt;P&gt;Instead of using SGPANEL, you could use SGPLOT with a BY statement, that will make one histogram per by-group.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2025 20:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-help-needed-How-to-create-separate-data-files-based-on/m-p/958764#M374173</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-02-08T20:27:33Z</dc:date>
    </item>
  </channel>
</rss>

