Counting the number of columns in a SAS dataset after a proc transpose.

Experts,

I have just run this step in SAS.

Proc transpose data=diags out=dx;
          by claim_id;
          var diag;
run:

My question is once the file is created I can look at it and see how many diag columns were generated.  I was just wondering if there was code to give me the results or to combine the next these two steps without manual intervention.  The number of columns will vary relative to the data.

My next step is: (assuming 10 columns were generated)
Data dx_rename;
     Set dx rename=col1-col10=dx10-dx10 drop=_name_ _label_);
run;
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IanStatisticianCommented:
Hi there morinia,

Yes,

using proc Contents will get the columns
proc contents data=dx;
ods output Variables=dxVariables(keep=Num Variable);
proc contents data=dx;
run;
ods listing;
title "List of variables in dx dataset";
proc print data=dxVariables noobs;
run;

Open in new window


using the SQL Dictionary  table "COLUMNS" (only available in proc SQL;
or the associated view VCOLUMNS which is available everywhere;

proc sql;
    select   varnum, name
    from    dictionary.COLUMNS
    where upcase(LIBNAME) =  "WORK" and
    upcase(MEMNAME) = "DX";
quit;

Open in new window


or

proc print data = sashelp.VCOLUMN noobs;
      where upcase(LIBNAME) =  "WORK" and
                 upcase(MEMNAME) = "DX";

	var name	varnum;
run;

Open in new window



====

But there is no need to do all that.

Proc transpose data=diags
                 out=dx(drop=_name_ _label_)
                 prefix="DX";
          by claim_id;
          var diag;
run:

Open in new window

will get you there without the mucking arround

Ian
1
IanStatisticianCommented:
The first code section had an extra line. Please delete the first  line as it is the same as line 3.
Code should be -

ods output Variables=dxVariables(keep=Num Variable);
proc contents data=dx;
run;

/* dataset  dxVariables  now has all the variable names
You could select a subset by     upcase(substr(name, 1, 2)) = "DX"     */ 

ods listing;
title "List of variables in dx dataset";
proc print data=dxVariables noobs;
run;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
moriniaAdvanced Analytics AnalystAuthor Commented:
This is exactly what I needed.  Since there was no need for the rename after using this code.

Proc transpose data=diags
                 out=dx(drop=_name_ _label_)
                 prefix=DX;
          by claim_id;
          var diag;
run:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.