I am trying to subset one CSV file into multiple CSV files. I wrote the codes below utilizing preserve and restore, and it's for one CSV file with 1150 records. It works.
Code:
import delimited "10_Exercise session.csv", clear scalar file_num=ceil(r(N)/100) preserve drop if _n>100 export delimited "10_Exercise session1.csv", replace restore preserve drop if 100<=_n & _n<200 export delimited "10_Exercise session2.csv", replace restore ... preserve drop if 1100<=_n export delimited "10_Exercise session12.csv", replace restore
I tried to use scalar for r(N) then use foreach command but failed. I don't think I have enough coding skills for this yet, so I would appreciate it if you can advise on how to write codes for the task.
Thank you.
0 Response to Subsetting a single CSV file into multiple CSV files
Post a Comment