BookmarkSubscribeRSS Feed
G-Scott
Fluorite | Level 6
I am so sorry if this is too simple of a question, I have gone over SAS literature and can’t seem to find a good answer.

I have some variables I have transposed in a data set. For some of my observations I have as many as 56 dates, so when I transpose I get 56 new variables.

I am wanting to create a variable based off of the 56 variables created during the transpose process. I want to select the first date in 2020;

So if var1 = 11/19/19
Var2= 1/3/20
Var3= 2/7/20

The new variable would be 1/3/20.

Is this possible?
3 REPLIES 3
MelissaM
Obsidian | Level 7

How about this?

data have;

input obs date date11.;

FORMAT DATE DATE9.;

datalines;

 

1 19/NOV/2019

2 03/JAN/2020

3 07/FEB/2020

;

Option #1

data want;

set have;

where date gt '01jan2020'd;

run;

proc transpose data=want out=want_t;

var date;

run;

Option #2

proc transpose data=have out=want;

where date gt '01jan2020'D;

var date;

format COL1 COL2 COL3 date9.;

run;

PaigeMiller
Diamond | Level 26

You could use the MIN function in a DATA step

 

Like this:

data want;
    set have;
    newvariable=min(of var1-var56);
run;

Although I point out that transposing is not necessary in this case, PROC SUMMARY will find minimums from the un-transposed data.

--
Paige Miller
Astounding
PROC Star

It doesn't seem like transposing the data was helpful.  But you can still get what you want in this fashion:

 

data want;
set have;
array dates {56} var1-var56;
do _n_=1 to 56;
   if year(dates{_n_}) = 2020 then earliest = min(earliest, dates{_n_});
end;
run;

This assumes that the date variables really are dates, and not character strings.  Looking at your post, I'm suspicious, but you will have to check that and correct it if necessary.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 416 views
  • 0 likes
  • 4 in conversation