DATA Step, Macro, Functions and more

Data Saparation

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Data Saparation

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.??


Accepted Solutions
Solution
‎04-30-2018 08:02 AM
PROC Star
Posts: 2,319

Re: Data Saparation

Posted in reply to Son_Of_Krypton
data N(keep=_NUMERIC_) 
     C(keep=_CHARACTER_);
  set SASHELP.CLASS;
run;

View solution in original post


All Replies
PROC Star
Posts: 1,218

Re: Data Saparation

Posted in reply to Son_Of_Krypton

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;
New Contributor
Posts: 4

Re: Data Saparation

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

Super User
Posts: 10,699

Re: Data Saparation

Posted in reply to Son_Of_Krypton
data CharacterVars;
    set have;
    keep _numeric_;
run;

data NumericVars;
    set have;
    keep _character_;
run;
Solution
‎04-30-2018 08:02 AM
PROC Star
Posts: 2,319

Re: Data Saparation

Posted in reply to Son_Of_Krypton
data N(keep=_NUMERIC_) 
     C(keep=_CHARACTER_);
  set SASHELP.CLASS;
run;
New Contributor
Posts: 4

Re: Data Saparation

Thanks for the solution

Super User
Super User
Posts: 9,441

Re: Data Saparation

Posted in reply to Son_Of_Krypton

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 147 views
  • 6 likes
  • 5 in conversation