<?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: Combine state counties to regions in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/613249#M81339</link>
    <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/17988"&gt;@jkeighley&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the script below to successfully update the regions into &lt;SPAN&gt;US-County-Name.jmp. Note that the script below does not save this file, or modify the associated XY file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
clear log();

/* This block opens &amp;amp; readies US-County-Name.jmp */
countylist = open( "C:/Program Files/SAS/JMP/17/Maps/US-County-Name.jmp" );
countylist &amp;lt;&amp;lt; New column( "County", formula( Word( 1, :Full Name Short, " " ) ) );
countylist &amp;lt;&amp;lt; New column( "Region", Character );
countylist &amp;lt;&amp;lt; New column( "State", formula( Word( -1, :Full Name Short, " " ) ) );

/*  This block opens the downloaded PDF */
// Opens downloaded PDF &amp;amp; imports the first table
request = New HTTP Request(
	URL(
		"https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246"
	),
	Method( "Get" )
);
file = request &amp;lt;&amp;lt; Download( "$TEMP/Kansas Health Preparedness Regions.pdf", "replace", "show_progress" );
dt = Open( file,
		PDF Tables(
		Table(
			table name(
				"Kansas Health Preparedness Regions and Map Page(1)  Table(1)"
			),
			add rows( page( 1 ), Rect( 0.4789, 1.0156, 10.5211, 7.8894 ) )
		)
	)
);

// For some reason, if the below command doesn't re-assign dt to the data table,
// dt isn't the correct data type for the operation to continue
dt = dt[1];

// Deletes empty rows in imported PDF table
dt &amp;lt;&amp;lt; Select where( Is Missing( :Region ) ) &amp;lt;&amp;lt; Delete Rows;

// Starting AA for data storage
region = Associative array();

// Stores region / county list data in AA
for( i = 1, i &amp;lt;= N Rows( dt ), i++,
	
	// Save the list as the value pair (county list, list of strings) to the respective key
	region[ dt:region[i] ] = words( dt:Counties Included[i], ", " );
	
);

// The region &amp;amp; county list is now stored in an AA!
//print( region );

kskeys = region &amp;lt;&amp;lt; Get keys;

/* This block will use data in AA to assign region to respective county in US-County-Name.jmp */
for( k = 1, k &amp;lt;= N rows( countylist ), k++,

	// Condition where state = Kansas
	try( if( countylist:State[k] == "KS",
		
		// Iterates through AA keys (regions)
		for( m = 1, m &amp;lt;= N Items( kskeys ), m++,
				
			// Checks if Count present, then assigns region to dt
			if( contains( region[ kskeys[m] ], countylist:County[k] ), // County is in m list
				
				countylist:Region[k] = kskeys[m]
				
			);			
		);		
	) ); // try --&amp;gt; if county not found in PDF stated counties, no region will be assigned
);

// Closes out pdf table, if needed
close( dt, "No Save" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Mar 2023 18:41:54 GMT</pubDate>
    <dc:creator>StarfruitBob</dc:creator>
    <dc:date>2023-03-16T18:41:54Z</dc:date>
    <item>
      <title>Combine state counties to regions</title>
      <link>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/601151#M80452</link>
      <description>&lt;P&gt;Kansas has 105 counties that are combined into 16 Health preparedness regions. How can I do this using the&amp;nbsp;US-County-Name.jmp and the associated XY file?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 16 regions for Kansas are defined at the following link:&amp;nbsp;&lt;A href="https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246" target="_blank"&gt;https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:36:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/601151#M80452</guid>
      <dc:creator>jkeighley</dc:creator>
      <dc:date>2023-06-08T16:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Combine state counties to regions</title>
      <link>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/601441#M80478</link>
      <description>&lt;P&gt;Somebody may have an easier way, but I've done things like this and know it will work though it takes some effort.&amp;nbsp; First, I would download that region table you linked and then separate the counties using the comma as a delimiter (I usually use Excel for this stage, although it can be done in JMP).&amp;nbsp; Then I would restructure that table by stacking the counties so that there are 2 columns, one with the region and the other showing counties associated with each region (but as a single column).&amp;nbsp; Then you can make sure that the US-County-Name.jmp file has the same format for the county names as the file you created (such as adding the word "County" to the county name - make sure it matches exactly the way the county names look in the map file).&amp;nbsp; Then assign the map role to the County column you have created, linking it to the US-County-Name.jmp file using the correct named column in that file.&amp;nbsp; Since your new file will have a column for Region, you can use that in Graph Builder to overlay or color the regions on the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this is labor intensive but it's the only way I've done this in the past.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 13:37:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/601441#M80478</guid>
      <dc:creator>dale_lehman</dc:creator>
      <dc:date>2023-02-15T13:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Combine state counties to regions</title>
      <link>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/613237#M81338</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/17988"&gt;@jkeighley&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below I have some code that needs some debugging, but should be a solid place to start. Any other scripters that could improve the script below?&amp;nbsp; I'm sure there is much improvement needed!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Opens&amp;nbsp;&lt;SPAN&gt;US-County-Name.jmp &amp;amp; p&lt;/SPAN&gt;&lt;SPAN&gt;reps for searching later, by breaking apart state and county into new columns&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Downloads &amp;amp; opens the PDF you linked above, then imports the table on the first page&lt;OL&gt;&lt;LI&gt;Note - always review script before running on your local machine! This script downloads a PDF from the internet.&amp;nbsp; Check line 15, the URL string in the URL() argument&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Assigns creates an associative array (AA) of regions (keys) &amp;amp; counties (values) within the region &lt;EM&gt;&amp;lt;-- loop not working&lt;/EM&gt;&lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;I'm a beginning at regular expressions, so the regex expression is broken&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;The list of counties comes back as a single string, which regex is supposed to break apart&lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;County string example: "Barton, McPherson, Pawnee, Rice, Saline, Stafford"&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Needs to be list of strings: { "Barton", "McPherson", "Pawnee", "Rice", "Saline", "Stafford" }&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;In&amp;nbsp;US-County-Name.jmp...&lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;Uses a few nested loops to find rows where State = KS and other conditions&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;When a row where State = KS, look at country, then finds which region it corresponds to by searching through the AA and then assigning the region (key) the county (value) is assigned to&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Saves the Region (key) to the row's Region column&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
clear log();

/* This block opens &amp;amp; readies US-County-Name.jmp */
countylist = open( "C:/Program Files/SAS/JMP/17/Maps/US-County-Name.jmp" );
countylist &amp;lt;&amp;lt; New column( "County", formula( Word( 1, :Full Name Short, " " ) ) );
countylist &amp;lt;&amp;lt; New column( "Region", Character );
countylist &amp;lt;&amp;lt; New column( "State", formula( Word( -1, :Full Name Short, " " ) ) );

/* This block DOWNLOADS &amp;amp; opens the downloaded PDF &amp;amp; imports first page table */
request = New HTTP Request(
	URL(
		"https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246"
	),
	Method( "Get" )
);
file = request &amp;lt;&amp;lt; Download( "$TEMP/Kansas Health Preparedness Regions.pdf", "replace", "show_progress" );
dt = Open( file,
		PDF Tables(
		Table(
			table name(
				"Kansas Health Preparedness Regions and Map Page(1)  Table(1)"
			),
			add rows( page( 1 ), Rect( 0.4789, 1.0156, 10.5211, 7.8894 ) )
		)
	)
);

// For some reason, dt imports as a 1 item list of data tables
// Reassigns dt to a "Table" data type for further processing
dt = dt[1];

// Deletes empty rows in imported PDF table
dt &amp;lt;&amp;lt; Select where( Is Missing( :Region ) ) &amp;lt;&amp;lt; Delete Rows;

// Starting AA for data storage
region = Associative array();

// Stores region / county list data in AA
for( i = 1, i &amp;lt;= N Rows( dt ), i++,
	
	templist = {};
	temphold = dt:Counties Included[i];
	tempitems = N Items( words( dt:Counties Included[i], "," ) );
	show(tempitems);
	
	// Breaks apart country string into individual counties and adds them to templist
	for( n = 1, n &amp;lt;= tempitems, n++,
		iteration = eval( eval expr( expr( eval insert( "\^n^" ) ) ) );

        // Fix me! This is broken
		insert into( templist, regex( "^\!"(\w*),*\!"$", iteration ) );
	);

	// Save the list as the value pair (county list, list of strings) to the respective key
	region[ dt:region[i] ] = templist
);

// The region &amp;amp; county list is now stored in an AA!
//print( region );

/* This block will use data in AA to assign region to respective county in US-County-Name.jmp */
for( k = 1, k &amp;lt;= N rows( countylist ), k++,

	// Condition where state = Kansas
	try( if( countylist:State[k] == "KS", 
		
		// Iterates through AA keys (regions)
		for( m = 1, m &amp;lt;= N Items( kskeys ), m++,
			
			// Creates list of counties within m region
			tempvals = region[m];
			
			// Checks if Count present, then assigns region to dt
			if( contains( tempvals, countylist:County[k] ), // County is in m list
				
				countylist:Region[k] = kskeys[m]
				
			);			
		);		
	) ); // try --&amp;gt; if county not found in PDF stated counties, no region will be assigned
);

// Closes out pdf table, if needed
close( dt, "No Save" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 17:43:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/613237#M81338</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-03-16T17:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Combine state counties to regions</title>
      <link>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/613249#M81339</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/17988"&gt;@jkeighley&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the script below to successfully update the regions into &lt;SPAN&gt;US-County-Name.jmp. Note that the script below does not save this file, or modify the associated XY file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
clear log();

/* This block opens &amp;amp; readies US-County-Name.jmp */
countylist = open( "C:/Program Files/SAS/JMP/17/Maps/US-County-Name.jmp" );
countylist &amp;lt;&amp;lt; New column( "County", formula( Word( 1, :Full Name Short, " " ) ) );
countylist &amp;lt;&amp;lt; New column( "Region", Character );
countylist &amp;lt;&amp;lt; New column( "State", formula( Word( -1, :Full Name Short, " " ) ) );

/*  This block opens the downloaded PDF */
// Opens downloaded PDF &amp;amp; imports the first table
request = New HTTP Request(
	URL(
		"https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246"
	),
	Method( "Get" )
);
file = request &amp;lt;&amp;lt; Download( "$TEMP/Kansas Health Preparedness Regions.pdf", "replace", "show_progress" );
dt = Open( file,
		PDF Tables(
		Table(
			table name(
				"Kansas Health Preparedness Regions and Map Page(1)  Table(1)"
			),
			add rows( page( 1 ), Rect( 0.4789, 1.0156, 10.5211, 7.8894 ) )
		)
	)
);

// For some reason, if the below command doesn't re-assign dt to the data table,
// dt isn't the correct data type for the operation to continue
dt = dt[1];

// Deletes empty rows in imported PDF table
dt &amp;lt;&amp;lt; Select where( Is Missing( :Region ) ) &amp;lt;&amp;lt; Delete Rows;

// Starting AA for data storage
region = Associative array();

// Stores region / county list data in AA
for( i = 1, i &amp;lt;= N Rows( dt ), i++,
	
	// Save the list as the value pair (county list, list of strings) to the respective key
	region[ dt:region[i] ] = words( dt:Counties Included[i], ", " );
	
);

// The region &amp;amp; county list is now stored in an AA!
//print( region );

kskeys = region &amp;lt;&amp;lt; Get keys;

/* This block will use data in AA to assign region to respective county in US-County-Name.jmp */
for( k = 1, k &amp;lt;= N rows( countylist ), k++,

	// Condition where state = Kansas
	try( if( countylist:State[k] == "KS",
		
		// Iterates through AA keys (regions)
		for( m = 1, m &amp;lt;= N Items( kskeys ), m++,
				
			// Checks if Count present, then assigns region to dt
			if( contains( region[ kskeys[m] ], countylist:County[k] ), // County is in m list
				
				countylist:Region[k] = kskeys[m]
				
			);			
		);		
	) ); // try --&amp;gt; if county not found in PDF stated counties, no region will be assigned
);

// Closes out pdf table, if needed
close( dt, "No Save" );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2023 18:41:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Combine-state-counties-to-regions/m-p/613249#M81339</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-03-16T18:41:54Z</dc:date>
    </item>
  </channel>
</rss>

