[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: change formats dinamically
From:       TheSharpOne <sharp131 () HOTMAIL ! CO ! UK>
Date:       2010-01-29 9:51:49
Message-ID: 5114b024-abe8-47e6-b16b-039adc5a5f7a () r6g2000yqn ! googlegroups ! com
[Download RAW message or body]

This won't be exactly straightforward and you may run into issues but
as a base you coudl type something like the code below.
The steps to create the tables DataTypes and DataTable is just be
setting you what you describe above and so you will need to drop these
and replace these table names with whatever you have called the
tables.

Data DataTypes;
  Col_Name = "TYPE1";
  DataType = "CHAR";
  Length = "5";
  Format = "$5.";
  Output;
  Col_Name = "TYPE2";
  DataType = "NUMERIC";
  Length = "";
  Format = "8.";
  Output;
  Col_Name = "TYPE3";
  DataType = "NUMERIC";
  Length = "";
  Format = "8.";
  Output;
  Col_Name = "TYPE4";
  DataType = "CHAR";
  Length = "8";
  Format = "$8.";
  Output;
Run;
Data DataTable;
  P_HA_ID = 1;
  Type1 = 5;
  Type2 = 5;
  Type3 = 25;
  Type4 = 15;
  Output;
  P_HA_ID = 2;
  Type1 = 10;
  Type2 = 10;
  Type3 = 59;
  Type4 = 12;
  Output;
  P_HA_ID = 3;
  Type1 = 15;
  Type2 = 15;
  Type3 = 63;
  Type4 = 36;
  Output;
Run;

Data _NULL_;
  Set DataTypes end = last;
  Retain Rename;
  Length Rename $1024.;

  If _N_ = 1 Then Rename = '(Rename = ( ';

  Rename = Trim(Rename)!!' '!!Col_Name!!' = tmp_'!!Col_Name;

  If Last Then
  Do;
    Rename = Trim(Rename)!!'))';
    Call Symput('RenameList',Trim(Rename));
  End;
Run;
%Put &Renamelist;

Filename TempCode Catalog 'Work.ModTableAttrib';
Data _NULL_;
  Set DataTypes end=last;
  File TempCode("ModifyTable.sas");
  If _N_ = 1 Then
  Do;
    Put "Data New_DataTable (Drop = Tmp_:);"
       /" Set DataTable &RenameList;";
  End;

  If Length NE "" Then
  Do;
    If DataType = "CHAR" Then Put "Length " Col_Name "$" Length ";";
    Else Put "Length " Col_Name Length ";";
  End;
  Else Put "Length " Col_Name "8;";

  Put "Format " Col_Name Format ";";

  Put Col_Name " = tmp_" Col_Name ";"
      /;

  If Last Then Put "Run;";
Run;

%Include TempCode("ModifyTable.sas");
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic