PING  0.9
Statistical data handling and processing in production environment
list_to_var

Insert into a (possibly already existing) dataset a variable passed as an unformatted (i.e., unquoted and blank-separated) list of values.

%list_to_var(varlst, var, dsn, fmt=, sep=%quote( ), lib=WORK);

Arguments

  • varlst : unformatted (i.e., unquoted and blank-separated) list of strings;
  • var : name of the variable to use in the dataset;
  • fmt : (option) string used to specify the format of the variable, as accepted by ATTRIB, e.g. something like $10. for a CHAR variable; by default, fmt is not set, the variable will be stored as a CHAR variable;
  • sep : (option) character/string separator in output list; default: %quote( ), i.e. sep is blank.

Returns

  • dsn : output dataset; if the dataset already exists, then observations with missing values everywhere except for the variable &var (possibly not present in dsn) will be appended to the dataset;
  • lib : (option) output library; default (not passed or ' '): lib is set to WORK.

Example

The following instructions:

%let varlst=DE UK SE IT PL AT;
%list_to_var(&varlst, geo, dsn);

return in WORK.dsn the following table:

Obsgeo
1 DE
2 UK
3 SE
4 IT
5 PL
6 AT

Run macro %_example_list_to_var for more examples.

Note

If the dataset already exists and there is either no numeric, or no character variables in it, then the following warning will be issued:

WARNING: Defining an array with zero elements.

This message is not an error.

References

  1. Carpenter, A.L. (1997): "Resolving and using &&var&i macro variables".
  2. Tsykalov, E. (2003): "Processing large lists of parameters and variables with SAS arrays and macro language".
  3. Carpenter, A.L. (2005): "Storing and using a list of values in a macro variable".

See also

%var_to_list, %clist_to_var.