BookmarkSubscribeRSS Feed
newtriks
Obsidian | Level 7
DATA xlmergM;
SET xlmergM;
KEEP MRN date_of_visit tested_for_hcv hcv_result;
FORMAT date_of_visit DTDATE9.;
IF tested_for_hcv="Yes";
* IF date_of_visit >= '01dec2021'd;
IF '01dec2021'd <= date_of_visit <='31dec2021'd;
RUN;

Data was uploaded from Excel. Tried sorting with date_of_visit in mm/dd/yyyy format and got nowhere - couldn't even find a thread using this format. Converted to that in the code above and have tried several suggestions from older threads and none seem to work.  Tried "between" syntax several times and just spun my wheels. Any help  would be appreciated. Thanks!

4 REPLIES 4
PaigeMiller
Diamond | Level 26

If you have numeric SAS dates (is the variable DATE_OF_VISIT numeric?) then formats are irrelevant here. And if its not numeric, or not a SAS date value, then it won't work at all.

 

It would help if you showed us a portion of the data you are using in SAS (not in Excel). The best way to show us the SAS data set is as SAS data step code (instructions).


Also, see this: https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/068-29.pdf

--
Paige Miller
newtriks
Obsidian | Level 7

Yes, the variable is numeric per Proc Contents. Date_of_visit is (obviously) in the 2d column. Is this enough?

 

1E10017701JAN1960YesNegative 
2E100620101JAN1960YesNegative 
3E10067801JAN1960YesNegative 
4E101227101JAN1960YesNegative 
5E101262801JAN1960YesNegative 
6E101710301JAN1960YesNegative 
7E10174901JAN1960YesNegative 
8E102412701JAN1960YesNegative 
9E102610001JAN1960YesNegative 
10E102777401JAN1960YesNegative 
11E102804001JAN1960YesNegative 
12E10365901JAN1960YesNegative 
13E1039201JAN1960YesNegative 
14E1044601JAN1960YesNegative 
15E10459701JAN1960YesNegative 
16E10510301JAN1960YesNegative 
17E105570901JAN1960YesNegative 
18E10575101JAN1960YesNegative 
19E10575401JAN1960YesNegative 
20E1067101JAN1960YesNegative 
21E10787101JAN1960YesNegative 
22E10874301JAN1960YesNegative 
23E10880601JAN1960YesNegative 
24E109091401JAN1960YesNegative 
25E109167801JAN1960YesNegative
PaigeMiller
Diamond | Level 26

DATE_OF_VISIT is numeric, and appears to be a date value but a date/time format has been applied, or the numbers imported from Excel are gibberish. In this case (and in every case), following the instructions for presenting the data would lead to a definitive answer (and is to your benefit as you will get faster and better answers by providing the data in the requested format). As presented above, its not really clear to me what has happened.

--
Paige Miller
newtriks
Obsidian | Level 7

Ok, this is far more complicated than my paygrade but I'll do whatever is necessary. Bear with me because a lot of basic questions are incoming.

 

For the first bit of code, I entered

PROC SQL;
CREATE TABLE xlmergZ AS
select Date_of_Visit
into :varlist separated by ' '
from xlmergM;
QUIT;

 

... and got back the column of entries under the variable I asked for. So far so good I think.

The next code string in the example you cited is utter Greek to me, even with a SAS book at my side to refer to. Here's what it says: 

 

select case type

          when 'num' then

             case

                when missing(format) then cats(Name,':32.')

                else cats(Name,':',format)

             end

          else cats(Name,':$',length,'.')

       end

      into :inputlist separated by ' '

   from dictionary.columns

   where libname="&lib"

     and memname="&dsn"

;

 

I entered this:

 

PROC SQL;

CREATE TABLE xlmergY AS

select case Date_of_Visit

when 'num' then

case

when missing(format) then cats(Name,':32.')

else cats(Name,':',format)

end

else cats(Name,':$',length,'.')

end

into :inputlist separated by ' '

from dictionary.columns

where libname="&lib"

and memname="&dsn"

;

 

LOG returned the error that it did not recognize my variable date_of_visit.

I am sorry to require so much hand-holding but I am utterly lost. I appreciate that you need this info to answer my question, and I am trying, but was already having trouble with the elementary code to upload a file in another format, and now I'm trying to write SQL code in order to get an answer to a far simpler question. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1603 views
  • 0 likes
  • 2 in conversation