我最近将两个数据集与一个非常简单的Merge
语句组合在一起。我正在使用ACS数据集和人口普查人口数据集。我需要后者的旗帜才能成为前者。当我合并时,地方变量(城镇/县,州)没有重复数据删除,因为一个数据集使用州缩写而另一个使用完整拼写:
Obs GeoID GeoName
1 . Abbeville County, SC
2 45001 Abbeville County, South Carolina
我需要更改Obs1
的GeoName,使其等于Obs2
index
功能会有效吗?或者我需要TRANWRD
功能吗?感谢。
解决:
data _null_;
length geoName $100;
GeoName_C = scan(GeoName,1,',');
GeoName_S = scan(GeoName,-1,','); *-1 scans from the right in case you could have commas in the city - check for this and adjust GeoName_C to include them if it is possible;
GeoName_S_F = stnamel(strip(GeoName_S));
GeoName = catx(',',GeoName_C,GeoName_S_F);
put _all_;
run;
答案 0 :(得分:0)
我要做的是将城市与州分开,并使用SAS的内置功能stnamel
将缩写转换为全名。
data _null_;
length geoName $100;
GeoName='Abbeville Road, SC';
GeoName_C = scan(GeoName,1,',');
GeoName_S = scan(GeoName,-1,','); *-1 scans from the right in case you could have commas in the city - check for this and adjust GeoName_C to include them if it is possible;
GeoName_S_F = stnamel(strip(GeoName_S));
GeoName = catx(',',GeoName_C,GeoName_S_F);
put _all_;
run;