KyleM_Corrie Tracker
https://communities.sas.com/kntur85557/tracker
KyleM_Corrie TrackerFri, 19 Jul 2024 12:08:43 GMT2024-07-19T12:08:43ZResolving a macro value as a date
https://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-value-as-a-date/m-p/260965#M310107
<P>I run a program that gives me different results based on specific parameters.</P>
<P> </P>
<P>I then use PROC SQL with the INTO clause to create macro variables based on those results. One of the variables created is the numerical date value from a data set. This is, of course, stored as a character variable when the macro vaariable is created.</P>
<P> </P>
<P>I then want to create a number of time-series plots with SGPLOT. I'd like to use the value of those date macro variables in the creation of the plots where the extracted date value is resolved in the SGPLOT procedure.</P>
<P> </P>
<P>For example,</P>
<P> </P>
<PRE><CODE class=" language-sas">%let Date=17543
proc sgplot data=uscpi;
series x=date y=cpi / markers;
format date yyqc.;
xaxis values=("&date"d to "1jul10"d by qtr);
run;</CODE></PRE>
<P>Is there a decent way to resolve a macro variable in this fashion?</P>Sun, 03 Apr 2016 23:42:02 GMThttps://communities.sas.com/t5/SAS-Programming/Resolving-a-macro-value-as-a-date/m-p/260965#M310107KyleM_Corrie2016-04-03T23:42:02ZClustering Effect Evaluation
https://communities.sas.com/t5/SAS-Programming/Clustering-Effect-Evaluation/m-p/260711#M50628
<P>I've been trying to come up with a method to evaluate how certain stores sales may or may not be affected once an identical store is introduced within a given proximity. With the help of some of you, I've been introduced to some pretty clever ideas to get it going.</P>
<P> </P>
<P>However, in order to make this process more replicable, I think I need to be more specific. So, my end goal is to be able to evaluate average store sales for the time period each new store is introduced.</P>
<P> </P>
<P><STRONG>To begin:</STRONG></P>
<P> </P>
<P>I have a data set filled with store information (an identifier, when it opened, latitude, longitude). With a combination of macro variables, SQL, and the GEODIST function, I am able to run a program that produces which stores opened within a given year (e.g., 2006), and which stores already existed (within a selected distance) when that new store opened.</P>
<P> </P>
<P>So, my results would look like the following:</P>
<P> </P>
<P><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2588i6FD8E273F3ABAF95/image-size/original?v=mpbl-1&px=-1" border="0" alt="cap1.PNG" title="cap1.PNG" /></P>
<P>Each unique value of <STRONG>N_Store</STRONG> represents a store that opened during 2006 and into a 1 mile radius of an existing store. Each value of <STRONG>E_Store</STRONG> represents those existing stores which were within a 1-mile radius of the newly opened store.</P>
<P> </P>
<P>Now, this is where I'm having trouble.</P>
<P> </P>
<P>I want to use this information in conjunction with a sales data set to see if, all else constant, this range affected sales of existing stores.</P>
<P> </P>
<P>An abbreviated version of that sales data would like like the following:</P>
<P> </P>
<P><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2591iCA282C6618131BA2/image-size/original?v=mpbl-1&px=-1" border="0" alt="cap2.PNG" title="cap2.PNG" /></P>
<P>So, when store 570 opened on June 6, 2006, stores 156, 531, 406, 499, and 385 already existed within a 1-mile radius. Then, later when store 752 opened on June 20, 2006, store 492 already existed within a 1-mile radius.</P>
<P> </P>
<P><STRONG>My goal:</STRONG></P>
<P> </P>
<P>I'd like to calculate the average of all stores, which already existed, for the time period before the new store was introduced. For example, for stores 156 through 385, the period would be from May 30, 2006 and before. For store 492, the period would be June 13, 2006 and before.</P>
<P> </P>
<P>Then I'd also like to know what they did 1 year, 2 years, 3 years after that store was introduced. So, for stores 156 through 385, I'd be looking at a 52/104/156 week average after June 6, 2006. Then, for store 492, a 52/104/156 week average from June 20, 2006.</P>
<P> </P>
<P>If anyone has any ideas on how this could be done, I'd love to hear them! If it can't be done, I'd love to hear that too!</P>
<P> </P>
<P>Thanks very much.</P>Fri, 01 Apr 2016 13:43:37 GMThttps://communities.sas.com/t5/SAS-Programming/Clustering-Effect-Evaluation/m-p/260711#M50628KyleM_Corrie2016-04-01T13:43:37ZCalculate multiple averages on same column
https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260458#M50543
<P>I'm hoping to find some method which will allow me to calculate multiple averages on the same columns for different time periods, and I'm not sure how or if it can be done.</P>
<P> </P>
<P>Some example data would be as follows:</P>
<P> </P>
<PRE><CODE class=" language-sas">data have;
format Date mmddyy10.;
input Date STR_3 STR_4 STR_7 STR_8;
datalines;
18917 . 17386 . 6756
18924 . 20913 . 9101
18931 . 19672 . 8734
18938 . 20362 . 9175
18945 . 21325 . 8749
18952 . 21129 . 8932
18959 . 21540 . 8374
18966 17714 19860 . 9645
18973 14983 22248 . 9055
18981 12833 20781 . 8709
18988 17347 21402 . 8886
18995 17295 22218 4400 9738
19002 17337 21577 3813 8830
19009 17402 23090 5052 10119
19016 17395 23426 5001 9480
19024 14114 24574 4361 9702
;
run;</CODE></PRE>
<P>And it looks like this:</P>
<P><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2572iF3ECCDA97A8EB65B/image-size/original?v=mpbl-1&px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /></P>
<P>Let's say I want to do the following:</P>
<OL>
<LI>Calculate an average of all observations for STR_3.</LI>
<LI>Calculate an average, using STR_4, for the period 10/17/2011 through 11/28/2011.</LI>
<LI>Calculate an average, using STR_4, for the period 12/05/2011 through 02/01/2012.</LI>
<LI>Calculate an average of all observations for STR_7.</LI>
<LI>Calculate an average, using STR_8, for the period 10/17/2011 through 12/27/2011.</LI>
<LI>Calculate an average, using STR_8, for the period 01/03/2012 through 02/01/2012.</LI>
</OL>
<P>It would seem I'm not clever enough to come up with some method, or I'm unaware of a procedure that would allow me to do something like that.</P>
<P> </P>
<P>Does anyone have any suggestions?</P>
<P> </P>
<P>Thanks</P>Thu, 31 Mar 2016 16:02:09 GMThttps://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260458#M50543KyleM_Corrie2016-03-31T16:02:09ZRe: Looking for an efficient method of comparison for distance
https://communities.sas.com/t5/Statistical-Procedures/Looking-for-an-efficient-method-of-comparison-for-distance/m-p/257786#M13636
<P>Thanks for the suggestions. I only mentioned the post count because I didn't see what other purpose your original post could have served.</P>
<P> </P>
<P>The method I described was only mentioned to describe what it was I hoped to achieve. It has been the only way I can figure out how to make it work, but I'd like to imagine there are much better methods.</P>
<P> </P>
<P>Currently, it requires me to import data that is stored in an XLSX file, create a new data set using PROC SQL which results in a Cartesian product, and then evaluate my conditions on the new data set in a different data step.</P>
<P> </P>
<P>It's not pretty, but it gets the job done.</P>
<P> </P>
<P>I was just curious if one of you guys had any way to make it pretty as well!</P>
<P> </P>
<P>Again, thanks much for the suggestions. It could be that what I want to do just can't be done in the manner I'd like it to be done.</P>Sat, 19 Mar 2016 23:58:46 GMThttps://communities.sas.com/t5/Statistical-Procedures/Looking-for-an-efficient-method-of-comparison-for-distance/m-p/257786#M13636KyleM_Corrie2016-03-19T23:58:46ZRe: Looking for an efficient method of comparison for distance
https://communities.sas.com/t5/Statistical-Procedures/Looking-for-an-efficient-method-of-comparison-for-distance/m-p/257784#M13634
<P>I'd like to find a method to accomplish this task without outputting a new data set and instead, hopefully, evaluate these conditions in the PDV.</P>
<P> </P>
<P>Do you have any suggestions, or were you just looking for an opportunity to increase your post count?</P>Sat, 19 Mar 2016 23:20:57 GMThttps://communities.sas.com/t5/Statistical-Procedures/Looking-for-an-efficient-method-of-comparison-for-distance/m-p/257784#M13634KyleM_Corrie2016-03-19T23:20:57ZLooking for an efficient method of comparison for distance
https://communities.sas.com/t5/Statistical-Procedures/Looking-for-an-efficient-method-of-comparison-for-distance/m-p/257781#M13632
<P>I'm trying to find a method of comparison for distance between particular locations that outputs only those observations that meet specific criteria.</P>
<P> </P>
<P>Take, for example, the following data set,</P>
<P> </P>
<PRE><CODE class=" language-sas">data HAVE;
input Store Lat Lon;
datalines;
1164 42.30861 -83.44031
1251 42.32282 -83.45289
1927 41.67517 -87.7969
6523 43.81187 -97.72712
;
run;</CODE></PRE>
<P>where <EM><STRONG>Store</STRONG> </EM>assigns an identifier code to a given store, <STRONG><EM>Lat</EM> </STRONG>identifies that store's geographical latitude, and <EM><STRONG>Lon</STRONG> </EM>identifies the stores geographical longitude.</P>
<P> </P>
<P>What I'd like to do is compare each store against every other store, calculate the distance between them using the GEODIST function, and then output only those stores which are within three miles of each other and not equal to zero.</P>
<P> </P>
<P><IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2380iF1AB2DE1D6F9D077/image-size/original?v=mpbl-1&px=-1" border="0" alt="comparisons.PNG" title="comparisons.PNG" /></P>
<P> </P>
<P>So, Store 1164 gets compared to Store 1164 and the GEODIST is calculated as 0.</P>
<P>Store 1164 gets compared to 1251 and the GEODIST is calculated as 1.17 miles.</P>
<P><SPAN>Store 1164 gets compared to 1927 and the GEODIST is calculated as 228.55 miles.</SPAN></P>
<P><SPAN>Store 1164 gets compared to 6523 and the GEODIST is calculated as 729.79 miles.</SPAN></P>
<P> </P>
<P><SPAN>Therefore, the only comparison which is output is the 1164 to 1251 comparison.</SPAN></P>
<P> </P>
<P><SPAN>Then the process repeats and Store 1251 is compared to all other stores.</SPAN></P>
<P> </P>
<P><SPAN>What I <EM><STRONG>don't</STRONG></EM> want to do is use multiple steps, create a Cartesian product using, another data set, and apply my logic qualifiers.</SPAN></P>
<P> </P>
<P><SPAN>I was hoping someone far more clever than I was out who had a more efficient method.</SPAN></P>
<P> </P>
<P><SPAN>I was wondering if it might be possible to put the HAVE data set in a SET statement, then use a DO loop, set the HAVE data set again, and calculate all distances then combine this with an OUTPUT statement to do everything in one go.</SPAN></P>
<P> </P>
<P><SPAN>I'd appreciate any suggestions!</SPAN></P>
<P> </P>
<P><SPAN>Thanks</SPAN></P>
<P> </P>
<P><SPAN>P.S. - The GEODIST function is as follows for anyone who is not familiar:</SPAN></P>
<P> </P>
<P><SPAN>=GEODIST(<EM>latitude1</EM>,<EM>longitude1</EM>,<EM>latitude2</EM>,<EM>longitude2</EM>, 'M')</SPAN></P>Sat, 19 Mar 2016 21:59:11 GMThttps://communities.sas.com/t5/Statistical-Procedures/Looking-for-an-efficient-method-of-comparison-for-distance/m-p/257781#M13632KyleM_Corrie2016-03-19T21:59:11ZRe: Calculating All GEODIST Combos
https://communities.sas.com/t5/Statistical-Procedures/Calculating-All-GEODIST-Combos/m-p/255170#M13462
<P>Hi, Reeza.</P>
<P> </P>
<P>Efficiency isn't a primary concern.</P>
<P> </P>
<P>Just a count is what I'm after, but a list of stores would be cool as well.</P>
<P> </P>
<P>Right now I'm messing with a DO loop idea. I've created a separate data set with just the latitude and longitude values, and I'm trying to do it that way. Just trying to come up with something. <span class="lia-unicode-emoji" title=":slightly_smiling_face:">ðŸ™‚</span></P>Tue, 08 Mar 2016 06:29:50 GMThttps://communities.sas.com/t5/Statistical-Procedures/Calculating-All-GEODIST-Combos/m-p/255170#M13462KyleM_Corrie2016-03-08T06:29:50ZCalculating All GEODIST Combos
https://communities.sas.com/t5/Statistical-Procedures/Calculating-All-GEODIST-Combos/m-p/255163#M13460
<P>Hello,</P>
<P> </P>
<P>I'm trying to come up with a way to calculate all distances between particular locations and run a tally of other locations that fall within particular ranges.</P>
<P> </P>
<P>For example, take this data set:</P>
<P> </P>
<PRE><CODE class=" language-sas">DATA TEMP;
INPUT STORE LATITUDE LONGITUDE;
DATALINES;
147 40.00376 -105.27621
193 40.58591 -105.00766
211 39.63461 -104.80849
245 40.39708 -104.69702
365 39.74437 -104.98742
384 40.55901 -105.09548
422 39.74773 -104.84025
449 39.58765 -104.86672
578 39.55761 -104.88142
584 40.57984 -105.05559
;
RUN;</CODE></PRE>
<P>I have ten separate stores and their locations.</P>
<P> </P>
<P>What I want to do is tally all the stores within three- and five-mile radiuses of each store.</P>
<P> </P>
<P>For example, </P>
<PRE><CODE class=" language-sas">DISTANCE=GEODIST(40.00376,-105.27621,40.58591,-105.00766, 'M');</CODE></PRE>
<P> </P>
<P>This value would give the distance, in miles, between stores 147 and 193. I want to repeat this process for stores 147 vs 211, 147 vs 245, etc. If this distance were less than or equal to 3 miles, I'd like to code a variable, <STRONG>MILE_3</STRONG>, as 1, otherwise zero. If this distance were less than or equal to 5 miles, I'd like to code a variable, <STRONG>MILE_5</STRONG>, as 1, otherwise 0. Then, I'd like a final tally record that resembled something like the following (where TOT_3 and TOT_5 are made up values for the number of stores in the data set within 3 and 5 miles of store 147).</P>
<P> </P>
<P>STORE LATITUDE LONGITUDE TOT_3 TOT_5</P>
<P>---------- ------------- ----------------- --------- ---------</P>
<P>147 40.00376 -105.27621 1 2</P>
<P>193 ... etc</P>
<P> </P>
<P>If possible, once store 147 is finished, I'd like store 193 to begin at the top and compare itself with store 147 so that its TOT_3 and TOT_5 values are accurate for itself.</P>
<P> </P>
<P>I'm just trying to find some way to do this, so if anyone far more clever than I has any suggestions, I'd love to try them. So far, the similar GEODIST topics haven't provided me the results I was after.</P>
<P> </P>
<P>Thanks much.</P>Tue, 08 Mar 2016 04:36:19 GMThttps://communities.sas.com/t5/Statistical-Procedures/Calculating-All-GEODIST-Combos/m-p/255163#M13460KyleM_Corrie2016-03-08T04:36:19ZPROC LOGISTIC, SELECTION=BACKWARD Variable Selection
https://communities.sas.com/t5/Statistical-Procedures/PROC-LOGISTIC-SELECTION-BACKWARD-Variable-Selection/m-p/254813#M13449
<P>I've been looking at the sample "SAS Statistical Business Analysis" exam questions at <A href="http://support.sas.com/certify/creds/samples/" target="_blank">http://support.sas.com/certify/creds/samples/</A></P>
<P> </P>
<P>Question #6 is as follows:</P>
<P> </P>
<DIV class="certquestion">Question 6</DIV>
<DIV class="indentlg">When selecting variables or effects using SELECTION=BACKWARD in the LOGISTIC procedure, the business analyst's model selection terminated at Step 3. <BR /><BR />What happened between Step 1 and Step 2?
<OL type="A">
<LI>DF increased.</LI>
<LI>AIC increased.</LI>
<LI>Pr > Chisq increased.</LI>
<LI>- 2 Log L increased.</LI>
</OL>
<STRONG>correct_answer = "D"</STRONG></DIV>
<P> </P>
<P>My question is: Shouldn't the answer be "C"? My understanding is that variable selection is based on a variable's p-value. The backward selection process, by default, eliminates variables one-by-one which don't meet the 0.10 criterion to "stay" in the model.</P>
<P> </P>
<P>Could someone please clarify if my understanding is wrong? If so, please explain why "D" is the correct answer.</P>
<P> </P>
<P>Thanks.</P>Sun, 06 Mar 2016 07:50:56 GMThttps://communities.sas.com/t5/Statistical-Procedures/PROC-LOGISTIC-SELECTION-BACKWARD-Variable-Selection/m-p/254813#M13449KyleM_Corrie2016-03-06T07:50:56ZRe: Creating data from PROC MEANS
https://communities.sas.com/t5/SAS-Programming/Creating-data-from-PROC-MEANS/m-p/237734#M268284
<P>I would just use an OUTPUT statement with an OUT= option.</P>
<P> </P>
<P>PROC MEANS DATA=SASHELP.CLASS<BR /> MEAN MIN MAX SKEW N;<BR /> OUTPUT OUT=WORK.NEWDATA;<BR />RUN;</P>
<P> </P>
<P>PROC PRINT DATA=WORK.NEWDATA;<BR />RUN;</P>
<P> </P>
<P>In the PROC MEANS statement just assign whatever options you'd like to display (if you don't want the default) and use the OUT= option to name the output data set.</P>Fri, 04 Dec 2015 03:36:09 GMThttps://communities.sas.com/t5/SAS-Programming/Creating-data-from-PROC-MEANS/m-p/237734#M268284KyleM_Corrie2015-12-04T03:36:09ZRe: SELECT Statement / Assigning Values
https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232603#M42406
<P>Thanks for the suggestions, guys.</P>
<P> </P>
<P>I think the easiest way was to add a system option.</P>
<P> </P>
<P>OPTIONS MISSING=0;</P>Sun, 01 Nov 2015 01:38:21 GMThttps://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232603#M42406KyleM_Corrie2015-11-01T01:38:21ZSELECT Statement / Assigning Values
https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232595#M42401
<P>Hello,</P>
<P> </P>
<P>I was wondering if there were some remedy for my issue. I have a data set, and I am creating new variables via an assignment statement based on the values of another variable from a select statement. However, when I do so, I'm left with missing variables in all of the other categories, and I'd like them to be assigned a value of zero instead.</P>
<P> </P>
<P>DATA HAVE;<BR />INPUT RACE1;<BR />DATALINES;<BR />1<BR />2<BR />3<BR />4<BR />5<BR />6<BR />7<BR />8<BR />9<BR />;<BR />RUN;</P>
<P> </P>
<P>DATA HAVE2;<BR />SET HAVE;<BR />SELECT (RACE1);<BR /> WHEN (1) WHITE=1;<BR /> WHEN (2) BLACK=1;<BR /> WHEN (3,4,5) NATIVE=1;<BR /> WHEN (6,7) ASIAN=1;<BR /> WHEN (8,9) OTHER=1;<BR />END;<BR />RUN;</P>
<P> </P>
<P>Is there any way to accomplish this with a select statement? I'm trying to avoid a complicated series of IF-THE/ELSE statements, and I've also done it with an ARRAY and DO loop combo, but I'm curious if there's just some simple I could use as part of this code to assign zeroes to all my missing values.</P>
<P> </P>
<P>Thanks.</P>Sat, 31 Oct 2015 22:27:36 GMThttps://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232595#M42401KyleM_Corrie2015-10-31T22:27:36Z