BookmarkSubscribeRSS Feed
maroulator
Obsidian | Level 7

My data looks like what I have in the attached .csv file and I need to have both variables sorted in ascending order. I tried using "proc sort" and "proc sql order by" to get the CDates sorted, but I have not been successful. I am thinking somekind of do-loop should do the trick, but at this point I am out of ideas.

Can anyone offer any insight?

2 REPLIES 2
Patrick
Opal | Level 21

It works for me with your data.

DATA WORK.Example;

   source_rec_num+1;

    LENGTH

        CouponDates        8

        CDates             8 ;

    FORMAT

        CouponDates      DATE9.

        CDates           DATE10. ;

    INFORMAT

        CouponDates      YYMMDD10.

        CDates           YYMMDD10. ;

    INFILE 'c:\temp\example.csv'

        DLM=','

        truncover

        DSD

        firstobs=2;

    INPUT

        CouponDates      : ?? YYMMDD8.

        CDates           : ?? YYMMDD8. ;

RUN;

proc sort data=work.example;

  by CouponDates CDates;

run;

data CDates_Not_Ascending;

  set work.example;

  if lag(CDates) > CDates then output;

run;

PGStats
Opal | Level 21

Also, given your date format (yymmdd.), sorting works even if you read the dates as character.  - PG

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 2 replies
  • 436 views
  • 0 likes
  • 3 in conversation