BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I have some non cdisc data sets with several variables. I am trying to convert it to cdisc sdtm datasets.  First step i am trying to rename all variables.  I am coping a sample data with the code i am trying.  Please suggest in my pgm where i am using arrays in data bbb.

I need help in the below data step bbb where i am trying to rename variables with arrays

eg: id to id_,

and then create id with cdisc compliance information such legnth and label etc . Thank you

 

 

data aaa;
input id ab $200. ac $200.;
datalines;
1 aaa bbb
2 abc bcd
3 bdb nan
;
proc contents data=aaa out=con;
run;
proc sql;
select count(distinct name) into:cntt trimmed from con;
select distinct name into :var1 -:var&cntt.
from con;
quit;
%put &cntt. &var1.;
data bbb;
set aaa;
 array aa(&cntt.) &var1. - &&var&cntt..;
 array aa_(&cntt.) &var1._ - &&var&cntt.._;;
 do i=1 to &cntt.;
 aa_(i)=aa(i);
 end;
 run;

 

output  

1 REPLY 1
ballardw
Super User

@knveraraju91 wrote:

Dear,

 

I have some non cdisc data sets with several variables. I am trying to convert it to cdisc sdtm datasets.  First step i am trying to rename all variables.  I am coping a sample data with the code i am trying.  Please suggest in my pgm where i am using arrays in data bbb.

I need help in the below data step bbb where i am trying to rename variables with arrays

eg: id to id_,

and then create id with cdisc compliance information such legnth and label etc . Thank you

 

 

data aaa;
input id ab $200. ac $200.;
datalines;
1 aaa bbb
2 abc bcd
3 bdb nan
;
proc contents data=aaa out=con;
run;
proc sql;
select count(distinct name) into:cntt trimmed from con;
select distinct name into :var1 -:var&cntt.
from con;
quit;
%put &cntt. &var1.;
data bbb;
set aaa;
 array aa(&cntt.) &var1. - &&var&cntt..;
 array aa_(&cntt.) &var1._ - &&var&cntt.._;;
 do i=1 to &cntt.;
 aa_(i)=aa(i);
 end;
 run;

 

output  


You might consider using Proc Datasets to rename things. If you have a very large file and/or many variables then the array approach takes a long time as you have to read each record. Proc datasets manipulates the data descriptors in place and is very fast.

 

proc sql;
   create table rename as
   select distinct name, cats(name,'_') as newname
   from dictionary.columns 
   where libname='WORK' and memname='AAA';
quit;

data _null_;
   set rename end=last;
   if _n_=1 then do;
      call execute ('Proc datasets library=work nodetails;');
      call execute ('modify aaa; rename');
   end;
   call execute(cats(name,'=',newname));
   /* the first ; ends the rename block*/
   if last then call execute(';run;quit;');
run;

This has a header executed with the first record to start the procedure and set the data set to manipulate (the modify statement, and starts the rename block. Then creates name=newname lines.

Proc Datasets supports run group processing so uses quit to end the procedure.

 

Important is that the library and member name (data set name) are stored as uppercase. So make sure the selection uses the appropriate case in the sql. The variable names can be mixed case so have not done anything to address that.

Caution: This really should include a check for variable names that are already 32 characters long and have a fix to avoid creating 33 character long names.

 

I have no clue what a cdisc index should look like so I'll stop here.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 1 reply
  • 308 views
  • 1 like
  • 2 in conversation