Help using Base SAS procedures

FUNCTION TO CHECK FIELD IS CHAR OR NUMERIC USING PROC SQL

Reply
Contributor
Posts: 38

FUNCTION TO CHECK FIELD IS CHAR OR NUMERIC USING PROC SQL

N stands for "Numeric" and C stands for 'Character'

(CASE
WHEN VTYPE(A.&FIRST)='N' AND A.&FIRST IS NOT NULL AND B.&SECOND IS NULL THEN A.&FIRST ELSE 0 END) AS NUMERIC_WRONG,
(CASE
WHEN VTYPE(A.&FIRST)='C' AND A.&FIRST IS NOT NULL AND B.&SECOND IS NULL THEN A.&FIRST ELSE '' END) AS CHARACTER_WRONG,

 

I have to seperate the buckets for character and numeric values in NUMERIC_WRONG and  CHARACTER_WRONG for one field..

The VTYPE function is working for DATA STEP but not for proc SQL. can any one tell me there is any function for proc sql which works same as VTYPE.

 

Your help is much appreciated. Thanks

Respected Advisor
Posts: 3,895

Re: FUNCTION TO CHECK FIELD IS CHAR OR NUMERIC USING PROC SQL

[ Edited ]

Your code snippet looks to me like you're overcomplicating something and that there must be a better solution. But then it doesn't show enough of what you have and want to achieve to really know.

 

Below would work in a SQL - doesn't mean I recommend doing it this way...

 


proc sql;
  select 
    (select type from dictionary.columns where libname='SASHELP' and memname='CLASS' and upcase(name)='SEX') as vtype_name,
    case
      when
        (select type from dictionary.columns where libname='SASHELP' and memname='CLASS' and upcase(name)='AGE') = 'num' then '1'
        else '0'
      end
    as vtype_ind_age
  from sashelp.class
  ;
quit;

 

Ask a Question
Discussion stats
  • 1 reply
  • 395 views
  • 0 likes
  • 2 in conversation