DATA Step, Macro, Functions and more

How to format a date within proc transpose statement

Reply
Contributor
Posts: 21

How to format a date within proc transpose statement

I need help trying to keep the variable admitDate formatted in the following code:

 

proc transpose data=temp
out=analysis
prefix=admitDate;
format admitDate yymmdd10.;
by patientId;
var age systolic procedure1 procedure2 procedure3 procedure4 procedure5 diagnosis1 diagnosis2 diagnosis3 diagnosis4 diagnosis5;
run;

 

**When I run it it gives the date as numbers. Is there a better way to do this?

Super User
Super User
Posts: 7,401

Re: How to format a date within proc transpose statement

Well, the best way is not to put data as column names.  Column names are there for your programming benefit, to ake your coding simpler and easier.  Creating columsn with numbers/dates or anything else will just make your life harder.  Prefix option is there give you a constant prefeix for all the data in the array, so you can refer to things via shorthand:

procedure:

You can't use that if the prefix changes each time.  That is one simple example, but there are many other reason why not to do it.  

Now variable label is a different matter - that is not used in programming, it is purely for display.  That can be anything you like.  You can set a label by:

proc transpose data=temp out=analysis;
  format admitDate yymmdd10.;
  by patientId;
  var age systolic procedure1 procedure2 procedure3 procedure4 procedure5 diagnosis1 diagnosis2 diagnosis3 diagnosis4 diagnosis5;
  idlabel admitdate;
  id admitdate;
run;

Note, I haven't tested if that is valid syntax as you have not provided any test data (form of datastep) or required output.

Contributor
Posts: 21

Re: How to format a date within proc transpose statement

Thank you. I will try it and see if it works.
Contributor
Posts: 21

Re: How to format a date within proc transpose statement

I tried it. Its not exactly what I am looking for. I don't need the dates as row headers. I would like an array like how mentioned in my initial code which is how I need the data organized. I just need each admit date to format as a date and not as Number. How can I do that using the prefix statement as an array to separate the admit dates in the code below:

 

proc transpose data=temp
out=analysis
prefix=admitDate;
format admitDate yymmdd10.;
by patientId;
var age systolic procedure1 procedure2 procedure3 procedure4 procedure5 diagnosis1 diagnosis2 diagnosis3 diagnosis4 diagnosis5;
run;

Super User
Super User
Posts: 7,401

Re: How to format a date within proc transpose statement

Then please show what you do require.  Provide test data in the form of a datastep, and what the output should look like.

Ask a Question
Discussion stats
  • 4 replies
  • 228 views
  • 0 likes
  • 2 in conversation