How to tokenize a extended macro (local :dir )?

拟墨画扇 提交于 2019-12-02 08:39:41

Various techniques spring to mind, none of which entails tokenizing.

local count = 1 
foreach file of local filelist {
    import excel "`file'",clear
    sxpose, clear 

    if `count' == 1 save alldata 
    else append using alldata 

    local ++count
}


local allothers "*" 
foreach file of local filelist {
    import excel "`file'",clear
    sxpose, clear 

    `firstonly'   save alldata 
    `allothers'   append using alldata 

    local firstonly "*" 
    local allothers 
}

In the second block, the point is that lines prefixed by * are treated as comments, so any command that * precedes is ignored ("commented out"). The append statement is commented out first time round the loop and the save statement is preceded by an undefined local macro, which evaluates to an empty string, so it is not ignored.

After the first time round the loop, commenting out on append is removed, but placed on the save.

I don't think either of these approaches is more efficient than what you have in mind (works faster, uses less memory, is shorter, or whatever "efficient" means for you). The code clearly does presuppose that you have set up the file list correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!