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

I have data with over 50 variables coded as 0-1. How do I specifically change the length of those variables without changing the other variables? 

data wide;
input enrolid x1$ x2 $ date1 date2 time;
datalines;1233   1 1 01/01/2012   . 111
4444  1 1  02/02/2012   .  33
666   0 1   .        02/03/2012  11
6666   0 1   03/03/2012 04/01/2012 11; 
run; 

  

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I would say the real question is why are you treating 0/1 coded variables as character at all. A great many things can be done with 0/1 numeric values easily that cannot be done quite as simply with character values.

 

Sum of the variables gives a count of 1 values

Mean of the variables give a percent of 1 values

Range of the variables can tell if all the variables are the same

 

 

Lengths are set when created. You could use an ATTRIB, LENGTH or INFORMAT statement prior to the INPUT to read the variables as desired. For example, assuming that you want the X variables to be length 1.

data wide;
   length x1 - x2 $ 1;
   input enrolid x1$ x2 $ date1 date2 time;
datalines;1233   1 1 01/01/2012   . 111
4444  1 1  02/02/2012   .  33
666   0 1   .        02/03/2012  11
6666   0 1   03/03/2012 04/01/2012 11; 
run; 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

You can not change the length of a variable once it is set. Why do you want to do this?

ballardw
Super User

I would say the real question is why are you treating 0/1 coded variables as character at all. A great many things can be done with 0/1 numeric values easily that cannot be done quite as simply with character values.

 

Sum of the variables gives a count of 1 values

Mean of the variables give a percent of 1 values

Range of the variables can tell if all the variables are the same

 

 

Lengths are set when created. You could use an ATTRIB, LENGTH or INFORMAT statement prior to the INPUT to read the variables as desired. For example, assuming that you want the X variables to be length 1.

data wide;
   length x1 - x2 $ 1;
   input enrolid x1$ x2 $ date1 date2 time;
datalines;1233   1 1 01/01/2012   . 111
4444  1 1  02/02/2012   .  33
666   0 1   .        02/03/2012  11
6666   0 1   03/03/2012 04/01/2012 11; 
run; 
lillymaginta
Lapis Lazuli | Level 10

Thank you! 

Tom
Super User Tom
Super User

Note an INFORMAT statement is for attaching informats to the variables, not defining their length.  If it is the first place where the variable is mentioned then it will have a side effect of forcing the compiler to guess what type/length to use for the variable.  The same way that the compiler will guess if some other statement, like INPUT or an assignment statement, is the first place the variable appears.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 2058 views
  • 2 likes
  • 4 in conversation