Hi Listers,
I have a time
series data file below and want to save it to different CSV files
using syntax based on Year and Month variables.
For example,
2009_05.csv for May 2009 data, 2009_06.csv for
June 2009 data, ..., 2011_10.csv for October 2011 data.
Thank in advance for any
assistance.
Boreak This email is intended solely for the named addressee. If you are not the addressee indicated please delete it immediately. |
Administrator
|
See below for a basic approach that works on some sample data I pulled from your listing. But of course, it would get really ugly if you made a copy of that for each year + month combination. Better to stick it into a macro that you hand a list of Year and Month combinations. I don't have time to write such a macro right now--it's time to go home and I'm hungry! But here are some thoughts on how you could approach it.
1. Use !CONCAT to build the file name. 2. For walking through two lists of macro arguments in lock-step, look up the !HEAD - !TAIL approach that David M has posted in the past. You can probably find it in the archives of this list. HTH. temporary. select if (year EQ 2009) and (month EQ 5). SAVE TRANSLATE OUTFILE='C:\temp\2009_05.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. temporary. select if (year EQ 2009) and (month EQ 6). SAVE TRANSLATE OUTFILE='C:\temp\2009_06.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
It would be much easier IMO to just use
the SPSSINC SPLIT DATASET extension command.
First create a string variable from the date variable: string s(a20). compute s = string(thedate, ADATE12). Then run this SPSSINC SPLIT DATASET SPLITVAR=s /OUTPUT DIRECTORY= "c:\temp\bydate". The output is one sav file for each value of s and named using those values. You also get a table in the Viewer of what was created. When you install the command you also get a dialog box for this. This requires the Python Essentials and the SPSSINC SPLIT DATASET extension command downloadable from the SPSS Community website at www.ibm.com/developerworks/spssdevcentral HTH, Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email] Date: 02/08/2012 04:26 PM Subject: Re: [SPSSX-L] Save data to different CSV files based on two variables Sent by: "SPSSX(r) Discussion" <[hidden email]> See below for a basic approach that works on some sample data I pulled from your listing. But of course, it would get really ugly if you made a copy of that for each year + month combination. Better to stick it into a macro that you hand a list of Year and Month combinations. I don't have time to write such a macro right now--it's time to go home and I'm hungry! But here are some thoughts on how you could approach it. 1. Use !CONCAT to build the file name. 2. For walking through two lists of macro arguments in lock-step, look up the !HEAD - !TAIL approach that David M has posted in the past. You can probably find it in the archives of this list. HTH. temporary. select if (year EQ 2009) and (month EQ 5). SAVE TRANSLATE OUTFILE='C:\temp\2009_05.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. temporary. select if (year EQ 2009) and (month EQ 6). SAVE TRANSLATE OUTFILE='C:\temp\2009_06.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. Boreak Silk wrote > > Hi Listers, > > I have a time series data file below and want to save it to different > CSV files using syntax based on Year and Month variables. > For example, 2009_05.csv for May 2009 data, 2009_06.csv for June 2009 > data, ..., 2011_10.csv for October 2011 data. > > > Date > Year > Month > Day > Hour > Mdate > Data_1 > Data_2 > 1-May-09 2009 5 6 0 1 17 25 > 1-May-09 2009 5 6 1 1 13 14 > 1-May-09 2009 5 6 2 1 10 3 > 1-May-09 2009 5 6 3 1 6 1 > 1-May-09 2009 5 6 4 1 7 2 > 1-May-09 2009 5 6 5 1 9 8 > 1-May-09 2009 5 6 6 1 15 22 > 1-May-09 2009 5 6 7 1 38 54 > 1-May-09 2009 5 6 8 1 72 124 > 1-May-09 2009 5 6 9 1 103 170 > 1-May-09 2009 5 6 10 1 145 219 > 1-May-09 2009 5 6 11 1 199 276 > 1-May-09 2009 5 6 12 1 312 420 > 1-May-09 2009 5 6 13 1 384 464 > 1-May-09 2009 5 6 14 1 301 401 > 1-May-09 2009 5 6 15 1 339 408 > 1-May-09 2009 5 6 16 1 364 454 > 1-May-09 2009 5 6 17 1 368 479 > 1-May-09 2009 5 6 18 1 291 400 > 1-May-09 2009 5 6 19 1 253 311 > 1-May-09 2009 5 6 20 1 227 278 > 1-May-09 2009 5 6 21 1 173 198 > 1-May-09 2009 5 6 22 1 161 182 > 1-May-09 2009 5 6 23 1 175 143 > 2-May-09 2009 5 7 0 2 108 92 > 2-May-09 2009 5 7 1 2 52 49 > 2-May-09 2009 5 7 2 2 52 32 > 2-May-09 2009 5 7 3 2 31 26 > 2-May-09 2009 5 7 4 2 23 11 > 2-May-09 2009 5 7 5 2 11 8 > 2-May-09 2009 5 7 6 2 11 12 > 2-May-09 2009 5 7 7 2 19 27 > > ........... > ... > ... > ... > ... > ... > ... > ... > 30-Oct-11 2011 10 1 9 30 61 90 > 30-Oct-11 2011 10 1 10 30 106 178 > 30-Oct-11 2011 10 1 11 30 179 296 > 30-Oct-11 2011 10 1 12 30 212 360 > 30-Oct-11 2011 10 1 13 30 216 320 > 30-Oct-11 2011 10 1 14 30 283 318 > 30-Oct-11 2011 10 1 15 30 315 366 > 30-Oct-11 2011 10 1 16 30 252 336 > 30-Oct-11 2011 10 1 17 30 206 232 > 30-Oct-11 2011 10 1 18 30 149 168 > 30-Oct-11 2011 10 1 19 30 105 123 > 30-Oct-11 2011 10 1 20 30 92 97 > 30-Oct-11 2011 10 1 21 30 70 63 > 30-Oct-11 2011 10 1 22 30 53 40 > 30-Oct-11 2011 10 1 23 30 38 34 > 31-Oct-11 2011 10 2 0 31 13 21 > 31-Oct-11 2011 10 2 1 31 8 7 > 31-Oct-11 2011 10 2 2 31 4 4 > 31-Oct-11 2011 10 2 3 31 3 2 > 31-Oct-11 2011 10 2 4 31 5 4 > 31-Oct-11 2011 10 2 5 31 6 9 > 31-Oct-11 2011 10 2 6 31 8 16 > 31-Oct-11 2011 10 2 7 31 25 46 > 31-Oct-11 2011 10 2 8 31 60 123 > 31-Oct-11 2011 10 2 9 31 106 214 > 31-Oct-11 2011 10 2 10 31 204 373 > 31-Oct-11 2011 10 2 11 31 316 491 > 31-Oct-11 2011 10 2 12 31 446 615 > 31-Oct-11 2011 10 2 13 31 463 569 > 31-Oct-11 2011 10 2 14 31 391 462 > 31-Oct-11 2011 10 2 15 31 378 425 > 31-Oct-11 2011 10 2 16 31 352 389 > 31-Oct-11 2011 10 2 17 31 341 360 > 31-Oct-11 2011 10 2 18 31 220 272 > 31-Oct-11 2011 10 2 19 31 187 233 > 31-Oct-11 2011 10 2 20 31 147 191 > 31-Oct-11 2011 10 2 21 31 116 142 > 31-Oct-11 2011 10 2 22 31 108 125 > 31-Oct-11 2011 10 2 23 31 165 96 > > > Thank in advance for any assistance. > > > Boreak > This email is intended solely for the named addressee. > If you are not the addressee indicated please delete it immediately. > ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Save-data-to-different-CSV-files-based-on-two-variables-tp5467853p5467997.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Hi Jon and Bruce,
Many thank for your help.
Regards,
Boreak
From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Jon K Peck First create a string variable from the date variable: string s(a20). compute s = string(thedate, ADATE12). Then run this SPSSINC SPLIT DATASET SPLITVAR=s /OUTPUT DIRECTORY= "c:\temp\bydate". The output is one sav file for each value of s and named using those values. You also get a table in the Viewer of what was created. When you install the command you also get a dialog box for this. This requires the Python Essentials and the SPSSINC SPLIT DATASET extension command downloadable from the SPSS Community website at www.ibm.com/developerworks/spssdevcentral HTH, Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] new phone: 720-342-5621 From: Bruce Weaver <[hidden email]> To: [hidden email] Date: 02/08/2012 04:26 PM Subject: Re: [SPSSX-L] Save data to different CSV files based on two variables Sent by: "SPSSX(r) Discussion" <[hidden email]> See below for a basic approach that works on some sample data I pulled from your listing. But of course, it would get really ugly if you made a copy of that for each year + month combination. Better to stick it into a macro that you hand a list of Year and Month combinations. I don't have time to write such a macro right now--it's time to go home and I'm hungry! But here are some thoughts on how you could approach it. 1. Use !CONCAT to build the file name. 2. For walking through two lists of macro arguments in lock-step, look up the !HEAD - !TAIL approach that David M has posted in the past. You can probably find it in the archives of this list. HTH. temporary. select if (year EQ 2009) and (month EQ 5). SAVE TRANSLATE OUTFILE='C:\temp\2009_05.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. temporary. select if (year EQ 2009) and (month EQ 6). SAVE TRANSLATE OUTFILE='C:\temp\2009_06.csv' /TYPE=CSV /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. Boreak Silk wrote > > Hi Listers, > > I have a time series data file below and want to save it to different > CSV files using syntax based on Year and Month variables. > For example, 2009_05.csv for May 2009 data, 2009_06.csv for June 2009 > data, ..., 2011_10.csv for October 2011 data. > > > Date > Year > Month > Day > Hour > Mdate > Data_1 > Data_2 > 1-May-09 2009 5 6 0 1 17 25 > 1-May-09 2009 5 6 1 1 13 14 > 1-May-09 2009 5 6 2 1 10 3 > 1-May-09 2009 5 6 3 1 6 1 > 1-May-09 2009 5 6 4 1 7 2 > 1-May-09 2009 5 6 5 1 9 8 > 1-May-09 2009 5 6 6 1 15 22 > 1-May-09 2009 5 6 7 1 38 54 > 1-May-09 2009 5 6 8 1 72 124 > 1-May-09 2009 5 6 9 1 103 170 > 1-May-09 2009 5 6 10 1 145 219 > 1-May-09 2009 5 6 11 1 199 276 > 1-May-09 2009 5 6 12 1 312 420 > 1-May-09 2009 5 6 13 1 384 464 > 1-May-09 2009 5 6 14 1 301 401 > 1-May-09 2009 5 6 15 1 339 408 > 1-May-09 2009 5 6 16 1 364 454 > 1-May-09 2009 5 6 17 1 368 479 > 1-May-09 2009 5 6 18 1 291 400 > 1-May-09 2009 5 6 19 1 253 311 > 1-May-09 2009 5 6 20 1 227 278 > 1-May-09 2009 5 6 21 1 173 198 > 1-May-09 2009 5 6 22 1 161 182 > 1-May-09 2009 5 6 23 1 175 143 > 2-May-09 2009 5 7 0 2 108 92 > 2-May-09 2009 5 7 1 2 52 49 > 2-May-09 2009 5 7 2 2 52 32 > 2-May-09 2009 5 7 3 2 31 26 > 2-May-09 2009 5 7 4 2 23 11 > 2-May-09 2009 5 7 5 2 11 8 > 2-May-09 2009 5 7 6 2 11 12 > 2-May-09 2009 5 7 7 2 19 27 > > ........... > ... > ... > ... > ... > ... > ... > ... > 30-Oct-11 2011 10 1 9 30 61 90 > 30-Oct-11 2011 10 1 10 30 106 178 > 30-Oct-11 2011 10 1 11 30 179 296 > 30-Oct-11 2011 10 1 12 30 212 360 > 30-Oct-11 2011 10 1 13 30 216 320 > 30-Oct-11 2011 10 1 14 30 283 318 > 30-Oct-11 2011 10 1 15 30 315 366 > 30-Oct-11 2011 10 1 16 30 252 336 > 30-Oct-11 2011 10 1 17 30 206 232 > 30-Oct-11 2011 10 1 18 30 149 168 > 30-Oct-11 2011 10 1 19 30 105 123 > 30-Oct-11 2011 10 1 20 30 92 97 > 30-Oct-11 2011 10 1 21 30 70 63 > 30-Oct-11 2011 10 1 22 30 53 40 > 30-Oct-11 2011 10 1 23 30 38 34 > 31-Oct-11 2011 10 2 0 31 13 21 > 31-Oct-11 2011 10 2 1 31 8 7 > 31-Oct-11 2011 10 2 2 31 4 4 > 31-Oct-11 2011 10 2 3 31 3 2 > 31-Oct-11 2011 10 2 4 31 5 4 > 31-Oct-11 2011 10 2 5 31 6 9 > 31-Oct-11 2011 10 2 6 31 8 16 > 31-Oct-11 2011 10 2 7 31 25 46 > 31-Oct-11 2011 10 2 8 31 60 123 > 31-Oct-11 2011 10 2 9 31 106 214 > 31-Oct-11 2011 10 2 10 31 204 373 > 31-Oct-11 2011 10 2 11 31 316 491 > 31-Oct-11 2011 10 2 12 31 446 615 > 31-Oct-11 2011 10 2 13 31 463 569 > 31-Oct-11 2011 10 2 14 31 391 462 > 31-Oct-11 2011 10 2 15 31 378 425 > 31-Oct-11 2011 10 2 16 31 352 389 > 31-Oct-11 2011 10 2 17 31 341 360 > 31-Oct-11 2011 10 2 18 31 220 272 > 31-Oct-11 2011 10 2 19 31 187 233 > 31-Oct-11 2011 10 2 20 31 147 191 > 31-Oct-11 2011 10 2 21 31 116 142 > 31-Oct-11 2011 10 2 22 31 108 125 > 31-Oct-11 2011 10 2 23 31 165 96 > > > Thank in advance for any assistance. > > > Boreak > This email is intended solely for the named addressee. > If you are not the addressee indicated please delete it immediately. > ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Save-data-to-different-CSV-files-based-on-two-variables-tp5467853p5467997.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |