I am fetching series from eurostat that end up having long names. Example:
Code: Select all
wfcreate a 1985 2017
fetch(d=eurostat) env_air_gge__airemsect=crf1-6x4_memo.airpol=ghg.freq=a.geo=lu.unit=ths_t env_air_gge__airemsect=crf1-6xmemo.airpol=ghg.freq=a.geo=lu.unit=ths_t env_air_gge__airemsect=crf1-6x4_memonia.airpol=ghg.freq=a.geo=lu.unit=ths_t- env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t env_air_gge__airemsect_crf1_6x4_memonia_airpol_ghg_freq_a_geo_lu_unit_ths_t env_air_gge__airemsect_crf1_6xmemo_airpol_ghg_freq_a_geo_lu_unit_ths_t
Code: Select all
@mid("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t", @instr("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t", "airemsect_") + @length("airemsect_"), @length("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t") - ( @length("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t") - @instr("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t", "_airpol") + @instr("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t", "airemsect_") + @length("airemsect_") ))Note that I cannot use @mid starting at crf1 and indicate a fix number as the string I want to extract changes length from object to object.
Now I would like to use the code above with temporary strings and values so I can use it in a loop, something in the lines of:
Code: Select all
%listseries = @wlookup("*","series")
group g1 {%listseries} 'avoid grouping resid and alpha objects
for !i=1 to g1.count
%strname = "g1.@seriesname(!i)"
%name = g1.@seriesname(!i)
!left =@instr({%strname}, "airemsect_") + @length("airemsect_")
!right = @length({%strname}) - @instr({%strname}, "_airpol")
%airemsect = "@mid({%strname}, {!left}, @length({%strname}) - ({!right} + {!left}))"
rename {%name} ghg_{%airemsect}_lu
next
delete g1Code: Select all
@instr("env_air_gge__airemsect_crf1_6x4_memo_airpol_ghg_freq_a_geo_lu_unit_ths_t", "airemsect_")In my example of 3 objects, it would of course be much faster to rename manually, but I intend on using the loop for many objects.
Could someone please have a look at my code and tell me where I am doing the mistake?
Thank you very much.
