SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Is it possible to create fields in a loop in DataFlux Data Management Studio?

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Is it possible to create fields in a loop in DataFlux Data Management Studio?

I need to create a number of fields within a for loop.

Is it possible to name them based on what iteration the loop is on?

IE:

Run:

a,b,c,d,e,f

1,2,3,1,2,3

through this code:

integer x

     for x = 1 to fieldcount()

          begin

          if (fieldvalue(x) >= 2)

               begin

               String above(x)

               above(x) = fieldvalue(x)

               end

          end

and get an output of:

a,b,c,d,e,f,above2, above3, above5,above6

1,2,3,1,2,3,2,3,2,3

If that is not possible, is it possible to call variables based on the iteration of a loop?

IE:

Run:

a,b,c,d,e,f

1,2,3,1,2,3

through this code:

integer x

String above1

String above2

String above3

String above4

String above5

String above6

     for x = 1 to fieldcount()

          begin

          if (fieldvalue(x) >= 2)

               begin

               above(x) = fieldvalue(x)

               end

          end

and get an output of:

a,b,c,d,e,f,above1,above2, above3, above4, above5,above6

1,2,3,1,2,3,(null),2,3,(null),2,3


Before you ask, nulling out numbers below 2 (columns a and d) would not be an option. Those fields are used in later calculations.


Thanks!


Accepted Solutions
Solution
‎10-09-2013 10:38 AM
SAS Employee
Posts: 33

Re: Is it possible to create fields in a loop in DataFlux Data Management Studio?

Hi,

To close the loop on this thread, I got the following response from one of our architects:

It is not possible to dynamically create fields at run-time inside an Expression node in a Data Management Platform Data Job. Even a construction like the sample code below does not work as declarations of fields are handled at “compile-time” and not at run-time:

   if condition

   begin

   // only create this field if
   the condition is true

   string special_field

   special_field=value

   end

There are functions though that allow you to interact dynamically with the set of fields that are available and allows you to loop through the list of defined fields, find data type and value of a field on an index, and set values. These functions would allow you to accomplish what is described in the blog posting. More details can be found in the Expression Language Reference Guide (see http://support.sas.com/documentation/onlinedoc/dfdmstudio/index.html), and look for functions like fieldcount(), fieldname(), fieldvalue(), fieldtype() and setfieldvalue() functions.

Here is a code snippet (taken from the above mentioned reference guide):

// Declare a hidden integer for the for loop,
initializing it to 0

hidden date field

hidden integer i

i = 0

hidden date Date_Field

// Checks each field to see if it is a date field

for i = 1 to FieldCount()

if FieldType(i) == 'Date' then

begin

Date_Field= FieldValue(i)

// If the date is in the future, then use
SETFIELDVALUE to set the value to null

if Date_Field > today()

SetFieldValue(i,null)

end

I hope that helps.

Mike F.

View solution in original post


All Replies
Occasional Contributor
Posts: 9

Re: Is it possible to create fields in a loop in DataFlux Data Management Studio?

MJames,

I just happen to see this post.  Did you figure out the answer to this Feb. 2013 question?

Thanks,

Brett

Solution
‎10-09-2013 10:38 AM
SAS Employee
Posts: 33

Re: Is it possible to create fields in a loop in DataFlux Data Management Studio?

Hi,

To close the loop on this thread, I got the following response from one of our architects:

It is not possible to dynamically create fields at run-time inside an Expression node in a Data Management Platform Data Job. Even a construction like the sample code below does not work as declarations of fields are handled at “compile-time” and not at run-time:

   if condition

   begin

   // only create this field if
   the condition is true

   string special_field

   special_field=value

   end

There are functions though that allow you to interact dynamically with the set of fields that are available and allows you to loop through the list of defined fields, find data type and value of a field on an index, and set values. These functions would allow you to accomplish what is described in the blog posting. More details can be found in the Expression Language Reference Guide (see http://support.sas.com/documentation/onlinedoc/dfdmstudio/index.html), and look for functions like fieldcount(), fieldname(), fieldvalue(), fieldtype() and setfieldvalue() functions.

Here is a code snippet (taken from the above mentioned reference guide):

// Declare a hidden integer for the for loop,
initializing it to 0

hidden date field

hidden integer i

i = 0

hidden date Date_Field

// Checks each field to see if it is a date field

for i = 1 to FieldCount()

if FieldType(i) == 'Date' then

begin

Date_Field= FieldValue(i)

// If the date is in the future, then use
SETFIELDVALUE to set the value to null

if Date_Field > today()

SetFieldValue(i,null)

end

I hope that helps.

Mike F.

New Contributor
Posts: 2

Re: Is it possible to create fields in a loop in DataFlux Data Management Studio?

As Mike F said, it seems that this functionality is not possible. I'm certainly hoping that dynamic field creation is added in the future, but I'm not holding my breath.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 631 views
  • 1 like
  • 3 in conversation