Как напечатать два набора переменных рядов рядом друг с другом в SAS? - PullRequest
1 голос
/ 12 февраля 2020

У меня есть набор данных SAS, в котором я храню 50 кодов диагнозов и 50 описаний диагнозов. Это выглядит примерно так:

data diags;
     set diag_list;
     keep claim_id diagcode1-diagcode50 diagdesc1-diagdesc50;
run;

Мне нужно распечатать все переменные, но мне нужно описание диагностики рядом с соответствующим кодом диагностики. Примерно так:

proc print data=diags;
    var claim_id diagcode1 diagdesc1 diagcode2 diagdesc2 diagcode3 diagdesc3; *(and so on all the way to 50);
run;

Есть ли способ сделать это (возможно, используя массивы) без необходимости вводить все это?

Ответы [ 2 ]

2 голосов
/ 12 февраля 2020

Вот один из подходов с использованием макросов. Если у вас есть другие переменные, обязательно включите их ДО части %loop_names(n=50) в операторе VAR.

*generate fake data to test/run solution;
data demo;
    array diag(50);
    array diagdesc(50);

    do claim_id=1 to 100;

        do i=1 to 50;
            diag(i)=rand('normal');
            diagdesc(i)=rand('uniform');
        end;
        output;
    end;
run;


%macro loop_names(n=);
    %do i=1 %to &n;
        diag&i  diagdesc&i. 
    %end;
%mend;


proc print data=demo;
    var claim_ID %loop_names(n=20);
run;
0 голосов
/ 13 февраля 2020

Вот пример кода SAS, который использует действительные коды CM ICD 10 и их описания, а также @Reeza proc print:

%* Copy government provided Medicare code data zip file to local computer;

filename cms_cm url 'https://www.cms.gov/Medicare/Coding/ICD10/Downloads/2020-ICD-10-CM-Codes.zip' recfm=s;
filename zip_cm "%sysfunc(pathname(work))/2020-ICD-10-CM-Codes.zip" lrecl=200000000 recfm=n ;

%let rc = %sysfunc(fcopy(cms_cm, zip_cm));
%put %sysfunc(sysmsg());

%* Define fileref to the zip file member that contains ICD 10 CM codes and descriptions;

filename cm_codes zip "%sysfunc(pathname(zip_cm))" member="2020 Code Descriptions/icd10cm_codes_2020.txt";

%* input the codes and descriptions, there are 72,184 of them;
%* I cheated and looked at the data (more than once) in order 
%* to determine the variable sizes needed;

data icd10cm_2020;
  infile cm_codes lrecl=250 truncover;
  attrib
    code length=$7
    desc length=$230
  ;
  input
    code 1-7 desc 9-230;
  ;
run;

* simulate claims sample data with mostly upto 8 diagnoses, and
* at least one claim with 50 diagnoses;

data have;
  call streaminit(123);
  do claim_id = 1 to 10;
    array codes(50) $7   code1-code50;
    array descs(50) $230 desc1-desc50;
    call missing(of code:, of desc:);

    if mod(claim_id, 10) = 0
      then top = 50;
      else top = rand('uniform', 8);

    do _n_ = 1 to top;
      p = ceil(rand('uniform', n));     %* pick a random diagnosis code, 1 of 72,184;
      set icd10cm_2020 nobs=n point=p;  %* read the data for that random code;
      codes(_n_) = code;
      descs(_n_) = desc;
    end;
    output;
  end;
  stop;
  drop top;
run;

%macro loop_names(n=);
    %do i=1 %to &n;
        code&i  desc&i. 
    %end;
%mend;

ods _all_ close;
ods html;


proc print data=have;
    var claim_id %loop_names(n=50);
run;
...