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

I have a table which contains  both character and numeric values and I want character values in one table and numeric values in another table how to do this.??

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20
data N(keep=_NUMERIC_) 
     C(keep=_CHARACTER_);
  set SASHELP.CLASS;
run;

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Do something like this

 

data have;
input Char1 $ Char2 $ Num1 Num2;
datalines;
ten twenty 10 20
thirty forty 30 40
fifty sixty 50 60
;

proc sql noprint;
    select name into :charVars separated by " " from dictionary.columns 
    where libname="WORK" and memtype="DATA" and memname="HAVE" and type="char";
    select name into :numVars separated by " " from dictionary.columns 
    where libname="WORK" and memtype="DATA" and memname="HAVE" and type="num";
quit;

%put &charVars.;
%put &numVars.;

data CharacterVars;
    set have;
    keep &charVars.;
run;

data NumericVars;
    set have;
    keep &numVars.;
run;
Son_Of_Krypton
Fluorite | Level 6

can we do this in data step without using macros.?? 

Ksharp
Super User
data CharacterVars;
    set have;
    keep _numeric_;
run;

data NumericVars;
    set have;
    keep _character_;
run;
ChrisNZ
Tourmaline | Level 20
data N(keep=_NUMERIC_) 
     C(keep=_CHARACTER_);
  set SASHELP.CLASS;
run;
Son_Of_Krypton
Fluorite | Level 6

Thanks for the solution

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Whilst you have the answer, I would ask why you want to do this?  I suspect you want to do some procedure on just num vars or something like that, in which case you don't need to.  You can use the automatic _numeric_ and _character_ to refere to either blocks pretty much anywhere, e.g.:

proc means data=have;
  var _numeric_;
run;

No need to split.

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
  • 6 replies
  • 1020 views
  • 6 likes
  • 5 in conversation