2017-04-05 150 views
0

我想獲取變量級別的數量以及唯一標識符輸出的變量,但是目前我的方法無法工作。然後我想使用proc freq中唯一的ID和關聯號碼1-num_levels。使用Proc Freq變量的輸出輸入到Proc格式

以下是我對PROC頻率:

PROC FREQ DATA=my_data (keep=IDs) nlevels; 
table all/out=out_data; 
%let dim=levels; 
%let IDs; 
run; 

然後我試圖使用宏變量,但它沒有工作,所以我包括我的PROC格式的手動版給個好主意我試圖達到的目標,但希望能夠讓它更加自動化。

PROC FORMAT; 
INVALUE INDEX 
"1234" = 1 
"2345" = 2 
. 
. 
. 
"8901" =25; 
/*25 represents the output of the levels 
variable from proc freq but I couldn't figure out how to grab that either*/ 
RUN; 

任何幫助,將不勝感激。 謝謝!

+1

查看使用CNTLIN數據集而不是宏變量。 – Reeza

+1

http://www2.sas.com/proceedings/sugi30/001-30.pdf – Reeza

+1

@Reeza是對的。您可以使用您手動創建的格式的CNTLOUT來查看CNTLIN數據集應該如何顯示 – keydemographic

回答

2

下面是一個完全可行的解決方案,它說明了PROC FORMAT CNTLIN的實現方法。這裏的想法是用觀察編號掩蓋姓名。

*Create list of unique names; 
proc freq data=sashelp.class noprint; 
    table name/out = mask; 
run; 

*create control data set. Variables that need to be set are: 
    fmtname, start, label and type; 

data name_fmt; 
    set mask; 
    fmtname = 'namefmt'; 
    type='J'; 

    *J specified character informat, C would be character format; 
    start=name; 
    label = put(_n_, z2.); *Use the row number as the recoded value; 
run; 

*create the format; 
proc format cntlin=name_fmt; 
run; 

*Sample usage; 
data class; 
    set sashelp.class; 
    name_masked = input(name, $namefmt.); 
    drop name; 
run; 
+0

謝謝!我昨天從您提供的資源中閱讀了這篇文章。我從來不知道cntlin! – hope288