BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ashna
Obsidian | Level 7

Hello,

 

I need to import an excel file with a where condition saying pull only col a with dateformat .

 

Example : I have a table with 3 columns as follows

Col A               Col B                 Col C

23/11/2018      Cars                  2000

24/10/2018      Buses               4000

Null 

                        test                  600          

 

When I import the above table into sas, I need to pull in data where Col A is non-empty and Col A has only dates.

proc import datafile =filepath 
out=work.input (where=(Not Missing(A) & A=date9.)) 
dbms=xlsx replace;
getnames=No;
run;

Can someone suggest best way to do this.

 

Thanks in advance all the help you provide 🙂

 

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

PROC IMPORT might not be the right way to do this, because it imports data guessing the rows. It may sometimes read date values as character. 

 

First import the data and then using a datastep or proc then modify your dataset. Since you have 'Null' as value I guess SAS will import that field as character. Convert the character to numeric and SAS will identify the format mentioned and gives missing if not valid.

 

proc import datafile =filepath 
out=work.input
dbms=xlsx replace;
getnames=No;
run;


data work.input;
set work.input(rename=(A=A_));
A=input(A_,ddmmyy10.); /* Which are not in ddmmyy format will have missing values */
if not missing(A);
run;
Thanks,
Suryakiran

View solution in original post

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

PROC IMPORT might not be the right way to do this, because it imports data guessing the rows. It may sometimes read date values as character. 

 

First import the data and then using a datastep or proc then modify your dataset. Since you have 'Null' as value I guess SAS will import that field as character. Convert the character to numeric and SAS will identify the format mentioned and gives missing if not valid.

 

proc import datafile =filepath 
out=work.input
dbms=xlsx replace;
getnames=No;
run;


data work.input;
set work.input(rename=(A=A_));
A=input(A_,ddmmyy10.); /* Which are not in ddmmyy format will have missing values */
if not missing(A);
run;
Thanks,
Suryakiran
Reeza
Super User
That may also result in a really messy log....

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2866 views
  • 0 likes
  • 3 in conversation