<?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 How to Create a New Variable Based on Frequency in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320793#M16945</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using the National Cancer Database and I would like to use the variable PUF_FACILITY_ID to create a new variable based on the frequency a facility ID appears. I've attached a screen shot of the printout of part of the PROC FREQ procedure for this variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the frequency with which the unique facility ID shows up, I would like to create a new variable based on this frequency. This would be a way to create a "Facility Volume" variable. From this new variable I would like to create percentiles and ultimately a dichotomous variable based off of a percentile cutoff.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13279iFDEB27381ED753C3/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="example.JPG" title="example.JPG" /&gt;</description>
    <pubDate>Thu, 22 Dec 2016 18:35:47 GMT</pubDate>
    <dc:creator>joshknut</dc:creator>
    <dc:date>2016-12-22T18:35:47Z</dc:date>
    <item>
      <title>How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320793#M16945</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently using the National Cancer Database and I would like to use the variable PUF_FACILITY_ID to create a new variable based on the frequency a facility ID appears. I've attached a screen shot of the printout of part of the PROC FREQ procedure for this variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the frequency with which the unique facility ID shows up, I would like to create a new variable based on this frequency. This would be a way to create a "Facility Volume" variable. From this new variable I would like to create percentiles and ultimately a dichotomous variable based off of a percentile cutoff.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13279iFDEB27381ED753C3/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="example.JPG" title="example.JPG" /&gt;</description>
      <pubDate>Thu, 22 Dec 2016 18:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320793#M16945</guid>
      <dc:creator>joshknut</dc:creator>
      <dc:date>2016-12-22T18:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320806#M16947</link>
      <description>&lt;P&gt;Since you are already familiar with PROC FREQ, that would be a good tool for the first step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have noprint;&lt;/P&gt;
&lt;P&gt;tables PUF_FACILITY_ID /&amp;nbsp;&lt;/P&gt;
&lt;P&gt;out=facility_counts (keep=PUF_FACILITY_ID rename=(count=Facility_Volume));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a SAS data set holding the facilities, and their volume (first two columns of your picture). &amp;nbsp;For creating percentiles, you can use PROC SUMMARY just to get a limited number of percentiles. &amp;nbsp;But PROC UNIVARIATE gives you much more flexibility as to which percentiles you can calculate.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 19:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320806#M16947</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-22T19:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320827#M16950</link>
      <description>Thank you for your quick reply!&lt;BR /&gt;&lt;BR /&gt;I tried to use all of your code, but I could not get the following code to run:&lt;BR /&gt;&lt;BR /&gt;(keep=PUF_FACILITY_ID rename= (count=Facility_Volume));&lt;BR /&gt;&lt;BR /&gt;So I omitted this and it worked well at creating what I needed. See (Attachment labeled "Code")&lt;BR /&gt;&lt;BR /&gt;However, it did create the variable that I desired (see attachment "Count Variable").&lt;BR /&gt;&lt;BR /&gt;I then tried to merge this new dataset with the COUNT term in the Main dataset (see attachment "Main Dataset"). I would like to merge based on the Case Key (PUF_CASE_ID) but I cannot, since this variable is not included in the new dataset with the new COUNT variable.&lt;BR /&gt;&lt;BR /&gt;How do I merge these two datasets by the Case Key?&lt;BR /&gt;&lt;BR /&gt;Thank you very much! This has been incredibly helpful.&lt;BR /&gt;&lt;BR /&gt;Josh&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;no attachments. -##</description>
      <pubDate>Thu, 22 Dec 2016 22:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320827#M16950</guid>
      <dc:creator>joshknut</dc:creator>
      <dc:date>2016-12-22T22:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320836#M16953</link>
      <description>&lt;P&gt;Show the code you used where the OUT= options did not work and any messages from the log. I suspect you may have inserted a ; wher not needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say you want to merge on PUF_CASE_ID. HOW is that related to PUF_FACILITY_ID? You did not mention that PUF_CASE_ID in the question at all. You will need to describe the relationship between the two variables or did you mean to count PUF_CASE_ID in the first place???&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2016 22:39:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320836#M16953</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-22T22:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320847#M16956</link>
      <description>&lt;P&gt;You're right about the error. &amp;nbsp;The KEEP= list should also include COUNT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;out=counts&amp;nbsp;&lt;SPAN&gt;(keep=PUF_FACILITY_ID &lt;FONT color="#FF0000"&gt;count&lt;/FONT&gt; rename= (count=Facility_Volume));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And yes, all you can merge by is PUF_FACILITY_ID. &amp;nbsp;Would that not do what you need?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 00:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320847#M16956</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-23T00:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320932#M16961</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;The new code you provided worked perfectly this time.&lt;BR /&gt;&lt;BR /&gt;I'll try to explain my main goal better and maybe you will be able to guide me on how to do that.&lt;BR /&gt;&lt;BR /&gt;In the main dataset, all of the variables are attached to a unique patient ID. Each patient was seen at a particular facility, indicated by their facility ID. I wanted to get the frequency of patients seen at each facility (the counts) to get a measure for the facility volume. Now I need to take that facility volume and make it a new variable in the main dataset, but linked to the unique patient ID. This way I'll be able to conduct a survival analysis based on facility volume.&lt;BR /&gt;&lt;BR /&gt;There are some 48,000 patients in the dataset and about 1,200 facilities. When I merged the data over, by facility ID, it just had 1,200 observations. I need to new Facility_Volume variable to have 48,000 observations, for each of the patients based on the volume of their Facility_ID.&lt;BR /&gt;&lt;BR /&gt;Is there a way to bring the patient ID over with the new data output when creating the Facility_Volume variable? That way I can merge it back by patient ID?&lt;BR /&gt;&lt;BR /&gt;Thanks for your help with this! We are almost to what I need to do. I really appreciate it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;no attachments. -##</description>
      <pubDate>Fri, 23 Dec 2016 14:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320932#M16961</guid>
      <dc:creator>joshknut</dc:creator>
      <dc:date>2016-12-23T14:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320958#M16962</link>
      <description>&lt;P&gt;You have a much better chance if link to the facility. I can see a strong likelihood of patients actually being seen at multiple facilities and so matching a single facility count to all records for the the patient could be terribly misleading.&lt;/P&gt;
&lt;P&gt;If you actually want the count of the patient visits at that facility then that is something else and would involve, if using Proc Freq a tables statement with both variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to post a small example of data, maybe 20 or 30 records.&amp;nbsp;Dummy data is fine as long as it shows a reasonable combination of facility patient data AND what the desired result for that example data would be. You can get instructions here &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; on how to turn a SAS data set into code that we can execute to recreate your data and test code with the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 15:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320958#M16962</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-23T15:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320995#M16963</link>
      <description>&lt;P&gt;If you can rely on the connection of each patient to one particular facility ID, you only need to get counts for each patient. &amp;nbsp;Similarly to what was done previously:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;tables patient_id / noprint out=counts (keep=patient_id count rename=(count=patient_volume));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then merge back into the original data by patient_id.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 19:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/320995#M16963</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-23T19:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Create a New Variable Based on Frequency</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/321000#M16964</link>
      <description>I got it to work! Thank you so much for your help&lt;BR /&gt;All of your assistance is greatly appreciated&lt;BR /&gt;&lt;BR /&gt;Happy Holidays&lt;BR /&gt;&lt;BR /&gt;Josh&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Dec 2016 19:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-to-Create-a-New-Variable-Based-on-Frequency/m-p/321000#M16964</guid>
      <dc:creator>joshknut</dc:creator>
      <dc:date>2016-12-23T19:50:06Z</dc:date>
    </item>
  </channel>
</rss>

