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

Hello,

I have numeric variables and characters that start with x.

I want to create two vectors as follows, but I can not. 

 

data tab1;
input id x1 x2 x3 x4 x5 x6 $ X7 $;
cards;
1 3 2 2 . 1 a b
1 . 1 1 3 2 . b
1 9 . 3 9 6 . b
1 8 . 7 3 2 a b
1 8 2 . 6 . a b
1 6 5 . . 9 a .
2 1 3 . 8 . . b
2 2 5 8 . . a b
2 3 3 11 . . a b
2 4 3 9 . 10 a b
;
run;

data tab2; set tab1; array Xnum(*) x: _numeric_; array Xchar(*) x: _CHARACTER_; /*Instructions*/ run;

 

 

Is there a possibility to do this in sas?

example:

use these options as functions

_numeric_ (x: )

_character_ (y: )

 

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's a variation that doesn't require you to sort through which are numeric and which are character. 

 

array nums {*} x1-numeric-x7;

 

array chars {*} x1-character-x7;

 

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just don't specify the x: part:

data tab1;
  input id x1 x2 x3 x4 x5 x6 $ X7 $;cards;1 3 2 2 . 1 a b1 . 1 1 3 2 . b1 9 . 3 9 6 . b1 8 . 7 3 2 a b1 8 2 . 6 . a b1 6 5 . . 9 a .2 1 3 . 8 . . b2 2 5 8 . . a b2 3 3 11 . . a b2 4 3 9 . 10 a b;
run;

data tab2;
  set tab1;  
  array xnum(*) _numeric_;
  array xchar(*) _character_;
/*Instructions*/
run;

True you will need to do a check to see if vname="id" and not do your logic for that one (as id is also numeric).

Otherwise you will need to build lists of variables from sashelp.vcolumn, which is harder.

Kurt_Bremser
Super User

Use from-to variable lists:

data tab1;
input id x1 x2 x3 x4 x5 x6 $ X7 $;
cards;
1 3 2 2 . 1 a b
1 . 1 1 3 2 . b
1 9 . 3 9 6 . b
1 8 . 7 3 2 a b
1 8 2 . 6 . a b
1 6 5 . . 9 a .
2 1 3 . 8 . . b
2 2 5 8 . . a b
2 3 3 11 . . a b
2 4 3 9 . 10 a b
;
run;

data tab2;
set tab1;
array Xnum(*) x1-x5;
array Xchar(*) x6-x7;
/*Instructions*/
run;
Astounding
PROC Star

Here's a variation that doesn't require you to sort through which are numeric and which are character. 

 

array nums {*} x1-numeric-x7;

 

array chars {*} x1-character-x7;

 

Ksharp
Super User

data tab2;
set tab1;
array Xnum(*) x1-numeric-x7;
array Xchar(*) x1-character-x7;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1981 views
  • 11 likes
  • 5 in conversation