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
Hi,
Sorry For Above Line where I mentioned With Instead Of without.So my concern is I want assign length without specifying variable names.
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.
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;
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.
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.
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!
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.