BookmarkSubscribeRSS Feed
dishant
Calcite | Level 5

Hi,

I have n number of character variables I want to assign length for all variables.Below is the peace of data.

Data have;

infile datalines missover;

input name$ surname$ id$;

datalines;

dishant parikh 101

dishantparikh makwana 10001

piyushpatel shah 10000000

;

Run;

Above data is example of original data. I want assign length for all variables with specifying variable names because there are around 300 character variables.

Your help will appreciate. Thanks in advance

Regards,

Dishant

5 REPLIES 5
dishant
Calcite | Level 5

Hi,

Sorry For Above Line where I mentioned With Instead Of without.So my concern is I want assign length without specifying variable names.

data_null__
Jade | Level 19

When working with large number of variables like this you will want to treat these names and other meta data (length type informat format label) like data.  Get the names and other meta data into a SAS data set then you can "program" the meta data into the statements you need to define them as variables.

Use the meta data data to generate ATTRIB statements into a file that you can %INC.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Generate the necessary:

Data have;
infile datalines missover;
input name$ surname$ id$;
datalines;
dishant parikh 101
dishantparikh makwana 10001
piyushpatel shah 10000000
;
Run;

data _null_;
  set sashelp.vcolumn (where=(libname="WORK" and memname="HAVE")) end=last;
  if _n_=1 then call execute('proc sql;
                                create table WANT as
                                select  '||strip(name)||' length=300');
  else call execute(','||strip(name)||' length=300');
  if last then call execute('   from HAVE;
                              quit;');
run;

Kurt_Bremser
Super User

You can use this:

length var1-varX $N;

X being the number of variables and N the desired length.

If the variables need to have different lengths/names, you will need to use macro programming or building the data step in a preceding data step using call execute.

dishant
Calcite | Level 5

HI All,

Sorry for late replay was unable to replay due to out of station.

Thanks to all for giving your valuable time its takes me new level of thinking.

Specially thanks to RW9 and data_null_ .Those solution inspired me and help me to solve my problem.

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