English 中文(简体)
SAS - Macro - Column name withspace/punctuation sign concerning alphabetically
原标题:SAS - Macro - Column names with spaces/punctuation marks troublesome when sorting alphabetically

我在《联合国系统会计准则》中有一大一栏代表世界各国。 我通过远距离转播建立了这一系统,我代表了每个国家的每个身份证的价值——见以下守则:

proc transpose data=basic_summarised out=cntrs_transposed (drop=_name_ _label_);
    by ID code;
    id country;
    var value;
run;

现在,我的目标是重新排列各栏,以便国家栏目在产出中出现。 为了做到这一点,我采取宏观行动:

%macro reorder_vars(Dataset);
proc sql noprint;
select compress(name,, kn ) into : dsn separated by " "
from dictionary.columns
where libname="%upcase(%scan(&dataset,1,.))" and memname="%upcase(%scan(&dataset,2,.))"
order by name
;
quit;
 
data %scan(&dataset,2,.);
retain ID code &dsn;
set &Dataset;
run;
%mend;
 
%reorder_vars(work.cntrs_transposed);

这一工作只针对有一字名字的国家,那些有图形标志或空间的国家,在变量清单的末尾(这些国家的例子有美国、刚果(共和国)等)。 我试图将压缩调压器改为粉碎机,认为它会消除校外和空间,但表没有变化。

我无法确定,在座是否有任何其他东西可以实现预期的结果?

感谢你们的帮助。

问题回答

在数据集中美国一栏的名称如何? 美国是不是美国人,还是美国人?

在RETAIN的声明中也需要使用同样的标记。

如果名称有空间,可使用核动力源。

proc sql noprint;
select nliteral(name) into : dsn separated by " "
from dictionary.columns
where libname="%upcase(%scan(&dataset,1,.))" and memname="%upcase(%scan(&dataset,2,.))"
order by name
;
quit;

因此,你为什么不把名字清单放在宏观变量中,这样你才能看到这些名字? 至少利用国家情报和安全局的职能确保名单有效,并利用国家情报和安全局(UPCASE)职能,美国将在美国进行分类。

proc sql noprint;
select nliteral(name) into :namelist separated by " "
 from dictionary.columns
  where libname="%upcase(%scan(&dataset,1,.))"
    and memname="%upcase(%scan(&dataset,2,.))"
  order by upcase(name)
;
quit;
 
data %scan(&dataset,2,.);
  retain ID code &namelist;
  set &Dataset;
run;




相关问题
How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

Can I Nest OrderBy in .NET?

This doesn t seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m) m.Sent).First.Sent) For Each d As Discussion In x ....

sorting elements javascript

I m looking for a way to sort my elements, but it isn t as easy as it sounds. Please let me explain My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all ...

热门标签