BookmarkSubscribeRSS Feed
didymo
Fluorite | Level 6

Is there an easier way than using proc transpose to divide many columns by a common value, such as 0.1, drop the original columns, and use the new columns divided by 0.1 when the data is in this format below?

 

SiteSubsiteTypeSampleDateYearAmphibiaNematomorphaBivalviaGastropodaDecapodaCollembolaEphemeroptera_UnknownEphemeroptera_BaeticidaeEphemeroptera_BaetidaeEphemeroptera_CaenidaeEphemeroptera_EphemerellidaeEphemeroptera_EphemeridaeEphemeroptera_HeptageniidaeEphemeroptera_IsonychiidaeEphemeroptera_LeptophlebiidaeOdonata_AshenidaeOdonata_CordulegastridaeOdonata_GomphidaePlecoptera_UnknownPlecoptera_ChloroperlidaePlecoptera_LeuctridaePlecoptera_NemouridaePlecoptera_PerlidaePlecoptera_PerlodidaePlecoptera_PeltoperlidaePlecoptera_PteronarcyidaePlecoptera_TaeniopterygidaeHempiptera_VeliidaeMegaloptera_CorydalidaeTichoptera_UnknownTichoptera_BrachycentridaeTichoptera_GlossosomatidaeTichoptera_HydropsychidaeTichoptera_LepidostomatidaeTichoptera_LeptoceridaeTichoptera_LimnephilidaeTichoptera_OdontoceridaeTichoptera_PhilopotamidaeTichoptera_PolycentrapodidaeTichoptera_RhyacophilidaeTichoptera_ThremmatidaeColeoptera_UnknownColeoptera_AnthicidaeColeoptera_CurculionidaeColeoptera_DytiscidaeColeoptera_DryopidaeColeoptera_ElmidaeColeoptera_HydrophilidaeColeoptera_PsephenidaeColeoptera_PtilodactylidaeDiptera_UnknownDiptera_CeratopogonidaeDiptera_ChironomidaeDiptera_DixidaeDiptera_EmpididaeDiptera_LimoniidaeDiptera_PediciidaeDiptera_PsychodidaeDiptera_SimuliidaeDiptera_TabanidaeDiptera_Tipulidae
PinchGutIndianCreek Reference15/18/202020000002004000102000720120200000050000040100000090000037000001300
PinchGutIndianCreek Reference25/18/2020200000000000202000001000000000000010000002000000012010001700200300
PinchGutIndianCreek Reference35/18/2020200000011000100000003000210000000220000000000000100000800000100
PinchGutIndianCreek Reference45/18/202020000000006030107000800050100000071000000000000117000004001200100
PinchGutIndianCreek Reference55/18/20202000000320200000000080005050000001120000000000000100100045000005500
PinchGutUT1_R4Treatment15/18/20202000000060000050800010001000000000000000000000001000103710401200
PinchGutUT1_R4Treatment25/18/2020200000001025000800000003056000000031200002000000001010214760219004100
PinchGutUT1_R4Treatment35/18/20202000000000100000100000000000000000000000000000001000023900100100
PinchGutUT1_R4Treatment45/18/202020000000000000706000101010000010000000000000000030100332400900000
PinchGutUT1_R4Treatment55/18/202020000000103200030000020004100000102300000000000000000057420026007500
PinchGutCandiff_M3Restored15/18/202020000000001000701000101060000000095000010010000010200074001200100
PinchGutCandiff_M3Restored25/18/202020000003403010460000100023171001010311040000500000000300000956109001200
PinchGutCandiff_M3Restored35/18/2020200000000013300000000000000000000001001000010000020100142800300000

 

I used the following which works but was curious if there is a better way. 

proc transpose data=step1a out=trans1; *(drop=_NAME_ _LABEL_);
var Amphibia Nematomorpha Bivalvia
Gastropoda Decapoda Collembola Ephemeroptera_Unknown Ephemeroptera_Baeticidae
Ephemeroptera_Baetidae Ephemeroptera_Caenidae Ephemeroptera_Ephemerellidae
Ephemeroptera_Ephemeridae Ephemeroptera_Heptageniidae Ephemeroptera_Isonychiidae
Ephemeroptera_Leptophlebiidae Odonata_Ashenidae Odonata_Cordulegastridae Odonata_Gomphidae
Plecoptera_Unknown Plecoptera_Chloroperlidae Plecoptera_Leuctridae Plecoptera_Nemouridae
Plecoptera_Perlidae Plecoptera_Perlodidae Plecoptera_Peltoperlidae Plecoptera_Pteronarcyidae
Plecoptera_Taeniopterygidae Hempiptera_Veliidae Megaloptera_Corydalidae Tichoptera_Unknown Tichoptera_Brachycentridae
Tichoptera_Glossosomatidae Tichoptera_Hydropsychidae Tichoptera_Lepidostomatidae Tichoptera_Leptoceridae Tichoptera_Limnephilidae
Tichoptera_Odontoceridae Tichoptera_Philopotamidae Tichoptera_Polycentrapodidae Tichoptera_Rhyacophilidae
Tichoptera_Thremmatidae Coleoptera_Unknown Coleoptera_Anthicidae Coleoptera_Curculionidae Coleoptera_Dytiscidae
Coleoptera_Dryopidae Coleoptera_Elmidae Coleoptera_Hydrophilidae Coleoptera_Psephenidae Coleoptera_Ptilodactylidae
Diptera_Unknown Diptera_Ceratopogonidae Diptera_Chironomidae Diptera_Dixidae Diptera_Empididae Diptera_Limoniidae
Diptera_Pediciidae Diptera_Psychodidae Diptera_Simuliidae Diptera_Tabanidae Diptera_Tipulidae pair;
by Site Subsite Type Sample Date Year Pair;
*proc print data=trans1;

data step1b;
set trans1;

density_m2=col1/0.09;
log_density_m2=log(density_m2+1); /* TRANSFORMATION ... */

if type="Referenc" then numberofstreams=3; else numberofstreams=5; /* WEIGHTING TO APPLY TO TYPE MEANS */
proc print data=step1b;

3 REPLIES 3
sbxkoenk
SAS Super FREQ

Hello,

Written "blind", so there may be errors :

/* query dictionary tables */  

PROC SQL noprint; select name into :OrigCols separated by ' ' from dictionary.columns where libname='MYLIB' and memname='MY_DS_NAME' and upcase(name) NOT IN ('SITE','SUBSITE','TYPE','SAMPLE','DATE','YEAR','PAIR') and upcase(type)='NUM'; select trim(name)!!'_NEW' into :NewCols separated by ' ' from dictionary.columns where libname='MYLIB' and memname='MY_DS_NAME' and upcase(name) NOT IN ('SITE','SUBSITE','TYPE','SAMPLE','DATE','YEAR','PAIR') and upcase(type)='NUM'; QUIT; %PUT &=OrigCols; %PUT &=NewCols; data work.want(drop=i drop=&OrigCols.); set MYLIB.MY_DS_NAME; array origC{*} &OrigCols.; array newC{*} &NewCols.; do i=1 to dim(origC); newC(i)=origC(i)/0.1; end; run; /* end of program */

Koen

ChrisNZ
Tourmaline | Level 20

Another way:

proc sql;
  select catt(NAME,'=',NAME,'/0.1') into :divide separated by ';'
  from DICTIONARY.COLUMNS
  where LIBNAME      ='MYLIB' 
    and MEMNAME      ='MY_DS_NAME'
    and upcase(NAME) not in ('SITE','SUBSITE','TYPE','SAMPLE','DATE','YEAR','PAIR')
    and upcase(TYPE) ='NUM';
quit;

data WANT;
  set MYLIB.MY_DS_NAME;
  ÷
run;

 

PaigeMiller
Diamond | Level 26

No transpose needed. Here is an example using SASHELP.CARS

 

data want;
    set sashelp.cars;
    array x msrp invoice enginesize cylinders horsepower; /* List all desired variables here */
    do i=1 to dim(x);
        x(i)=x(i)/0.1;
    end;
run;
--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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