顺序变量名语法



我正在努力编译我的大型数据集,并假设语法命令是答案,但是,我对语法并不熟练。我的问题是我应该使用什么语法命令(或其他方法)来创建数百/数千个新变量名,这样我就不需要手动操作了。

我正在研究一个数据集,涉及2012-2021年(10年)受害者中亲密伴侣杀人和家庭暴力服务的使用情况,每月检查一次(120个月)。在这段时间内,我有三个变量名称集(REC[接受服务的客户数量],CALL[服务电话数量],HOUR[律师/员工提供服务的小时数]),需要在2012年至2021年的10年间每月1月至12月重复,以及39个单独的服务。见下文:

MonthYear_REC_ServiceNameMonthYear_CALL_ServiceNameMonthYear_HOUR_ServiceName

"Month"以上为1-12月(01-12),"年";2012-2021(12-21)和"服务名称";将被39种不同的服务所取代。以2017年和"庇护所"为例;服务:

0117 _rec_shelter0117年_call_shelter0117年_hour_shelter0217年_rec_shelter0217年_call_shelter0217年_hour_shelter0317年_rec_shelter0317年_call_shelter0317年_hour_shelter…..以此类推,直到2017年12月。

进一步解释:对于我拥有数据的39项服务中的每一项,这个连续的月度订单需要在2012-2021年的时间框架内每年重复。"Shelter"服务如上面的例子所示,但我还需要在38种其他服务类型(如团体咨询、法律宣传、经济援助等)中使用相同的一组变量名。

我的总体问题是(抱歉重复)-我需要输入什么语法命令来创建大量的变量名/变量?我希望这对每个人都有意义,就像它对我有意义一样!很抱歉这么长时间,提前谢谢你。

最好的,香农h .

假设您想要创建一个包含您所描述的所有变量名称的空数据集,则可以这样做:

INPUT PROGRAM.
LOOP ind = 1 to (12*10*3*39).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.
do repeat vr=month year set service/vl=12 10 3 39.
compute vr=mod(ind,vl).
recode vr (0=vl).
compute ind=trunc((ind-1)/vl)+1.
end repeat.
compute year=year+11.
formats all (f2).
alter type month year (a2) set (a4).
compute month = char.lpad(ltrim(month), 2, "0").
recode set ("   1"="REC")("   2"="CALL")("   3"="HOUR").
* I suggest at this point you use "match files" to match the service numbers here with a list of service names.
* The following code creates fictitious service names instead to demonstrate how to use them.
string serviceName (a20) vrnm (a50).
compute serviceName=concat("service", char.lpad(ltrim(string(service, f2)), 2, "0") ).
* now to create the final variable names.
compute vrnm=concat(month, year, "_", set, "_", serviceNAme).
flip NEWNAMES  = vrnm.
select if CASE_LBL="".
exe.

最新更新