<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: print constant values assigned to column values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300724#M63559</link>
    <description>&lt;P&gt;List your steps out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tackle them one at a time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, use dictionary table to search for existence of columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second step is...,?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2016 10:45:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-09-26T10:45:10Z</dc:date>
    <item>
      <title>print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300698#M63549</link>
      <description>&lt;P&gt;data test1;&lt;BR /&gt;input name $15.;&lt;BR /&gt;cards;&lt;BR /&gt;sam&lt;BR /&gt;danny&lt;BR /&gt;jacob&lt;BR /&gt;susan&lt;BR /&gt;sandra&lt;BR /&gt;vinny&lt;BR /&gt;alicia&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data .test2;&lt;BR /&gt;input name $15.;&lt;BR /&gt;cards;&lt;BR /&gt;sam&lt;BR /&gt;dann&lt;BR /&gt;jhon&lt;BR /&gt;susan&lt;BR /&gt;sandy&lt;BR /&gt;vinny&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hello am trying to write a macro code which takes the file locations of tables &amp;amp; assigns libnames and takes tables from different datasets&lt;/P&gt;
&lt;P&gt;having common columns &amp;amp; assigining random values to the column variable if they are in the variable parameter.these assigined values remain constant throughought the tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example am having 2 datasets test1 &amp;amp; test2 with 'name' column common in both datasets then how do I take their location in macro parameter &amp;amp; assign &amp;nbsp;libname to them &amp;amp; assign the same random values to same values &amp;amp; to other values in name columns in both datasets.&lt;/P&gt;
&lt;P&gt;parameters--&amp;gt;indsn odsn filename variable&amp;nbsp;&lt;/P&gt;
&lt;P&gt;random value example '&lt;SPAN&gt;088PQRSDW'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 06:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300698#M63549</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-26T06:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300700#M63551</link>
      <description>&lt;P&gt;Note: in SAS speak, "table" and "dataset" usually has the same meaning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you want a macro that accepts a library and column name as parameters, then looks for tables in that library containing the named variable, and then fills that variable with random values, but the random values need to be uniform across tables for a given observation number? What if tables have different numbers of observations?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 07:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300700#M63551</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-26T07:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300701#M63552</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16120"&gt;@Kurt&lt;/a&gt; yes table dataset its same srry my mistake yes i want indsn= lib= odsn= variable= where ever in the diff tables name column is there the column values must be assigined random values like these '088PQRSDW' and same values as in my data sam vinny susan are in both datasets so they will have same random values which is constant throught.</description>
      <pubDate>Mon, 26 Sep 2016 07:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300701#M63552</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-26T07:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300702#M63553</link>
      <description>&lt;P&gt;Ah, I seem to see what you're up to.&lt;/P&gt;
&lt;P&gt;You want to anonymize key values across datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before putting it into a macro, do it step-by-step&lt;/P&gt;
&lt;P&gt;- set the values that are later to be macro parameters with %let (library,column)&lt;/P&gt;
&lt;P&gt;- retrieve the dataset names from dictionary.columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table datasets as select distinct memname from dictionary.columns
where upcase(libname) = upcase("&amp;amp;libname") and upcase(name) = upcase("&amp;amp;column")
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, collect all values from all datasets:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set datasets end=done;
if _n_ = 1 then call execute('data values;set ');
call execute("&amp;amp;libname.."!!strip(memname)!!' ');
if done then call execute(": keep &amp;amp;column; run;");
run;

proc sort data=values nodupkey;
by &amp;amp;column;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In a next data step, assign a random value to a new variable in values. Use a randomizing algorithm of your choice.&lt;/P&gt;
&lt;P&gt;Depending on the distinct count of values, you might then create a value format from your values, and use that in an automatically created sequence of data steps (see how I used call execute), or you might need to use call execute to create code for each dataset that does a join and sets the random values.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 07:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300702#M63553</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-26T07:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300706#M63554</link>
      <description>&lt;P&gt;how do i simple check the diffefrent table column values at a certain location through location_parameter &amp;amp; assign random values to them.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 10:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300706#M63554</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-26T10:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300707#M63555</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60507"&gt;@RTelang&lt;/a&gt; wrote:&lt;BR /&gt;how do i simple check the table column values &amp;amp; assign random values to them. use a lib parameter &amp;amp; assign the location in the macro call.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;#1 Read my post&lt;/P&gt;
&lt;P&gt;#2 You know how to use the libname statement, don't you? And how to use macro variables in program code?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 08:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300707#M63555</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-26T08:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300720#M63556</link>
      <description>&lt;P&gt;@kurtBrememer this I tried but i fail to understand how do i take location and check data-sets at that location see if the column exist then assign random values...&lt;BR /&gt;%macro val(lib=,ds=,libname=,column=);&lt;BR /&gt; libname myfile "&amp;amp;lib";&lt;BR /&gt;&lt;BR /&gt;%if %sysfunc(exist(myfile.&amp;amp;ds))=0 %then %do;&lt;BR /&gt; %if %sysfunc(exist(myfile.&amp;amp;ds,view))=0 %then&lt;BR /&gt; %do; &lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table datasets as select distinct memname from dictionary.columns&lt;BR /&gt;where upcase(libname) = upcase("&amp;amp;lib") and upcase(name) = upcase("&amp;amp;column");&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set datasets end=done;&lt;BR /&gt;if _n_ = 1 then call execute('data values;set ');&lt;BR /&gt;call execute("&amp;amp;lib.."!!strip(memname)!!' ');&lt;BR /&gt;if done then call execute(": keep &amp;amp;column; run;");&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=values nodupkey;&lt;BR /&gt;by &amp;amp;column;&lt;BR /&gt;run;&lt;BR /&gt; %end;&lt;BR /&gt; %end;&lt;BR /&gt; %quit:&lt;BR /&gt;%mend val;&lt;BR /&gt;%val(lib='C:\Users\Desktop\Myfiles',ds=test1,column=name);&lt;BR /&gt;&lt;BR /&gt;but gives error &lt;BR /&gt; Invalid physical name for library MYFILE.&lt;BR /&gt;ERROR: Error in the LIBNAME statement&lt;BR /&gt;.&lt;BR /&gt;File WORK.VALUES.DATA does not exist.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 10:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300720#M63556</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-26T10:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300722#M63557</link>
      <description>&lt;P&gt;It seems, from your posts, that you are fixed on macro language. &amp;nbsp;As mentioned in various other posts, Base SAS is the key language, Macro is nothing more than a text generator. &amp;nbsp;As such, look at your Base SAS code and get that working. &amp;nbsp;Just a look at your post there you have stated what the problem is:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Invalid physical name for library MYFILE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR: Error in the LIBNAME statement&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, strip out all the macro code, and get your code working as Base SAS, i.e. start with the code line:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;libname myfile "C:\Users\rtelang\Desktop\Myfiles";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Run that actual code in your SAS interactive window, does it work, does that folder exist, do you have access to it. &amp;nbsp;Once you have that running then add in the next datastep, get that working etc. until you have correct and functioning code. &amp;nbsp;Then maybe look at adding macro parts to it. &amp;nbsp;For instance, why bother having a call execute block, if your putting all this in macro language? &amp;nbsp;You can do this very simply in Base SAS:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set datasets end=done (where=(libname="&amp;lt;insert libname&amp;gt;" and name="&amp;lt;insert column&amp;gt;"));
  if _n_ = 1 then call execute('data values;set ');
  call execute(cats("&amp;lt;insert libname&amp;gt;.",memname)));
  if done then call execute("; keep &amp;lt;insert column name&amp;gt;; run;");
run;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Note the use of the code window.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 10:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300722#M63557</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-26T10:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300723#M63558</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; hmm thanks for d input but my concern is in a certain location there are 3 datasets with each having name variable as column.so i want to assign random values to the orininal name column values/ now am trying to use a generic macro with parameters to take indsn,odsn,variable,location as parameter so i can check any variable to assign random values to but if the value is same in diff columns then their random value should be constant...</description>
      <pubDate>Mon, 26 Sep 2016 10:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300723#M63558</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-09-26T10:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300724#M63559</link>
      <description>&lt;P&gt;List your steps out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tackle them one at a time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, use dictionary table to search for existence of columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second step is...,?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 10:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300724#M63559</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-26T10:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300731#M63560</link>
      <description>&lt;P&gt;Shouldn't matter:&lt;/P&gt;
&lt;P&gt;Step 1 - write Base SAS which does the job&lt;/P&gt;
&lt;P&gt;Step 2 - think about parameterising the code for macro purposes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 10:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300731#M63560</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-09-26T10:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: print constant values assigned to column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300736#M63561</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60507"&gt;@RTelang&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;@kurtBrememer this I tried but i fail to understand how do i take location and check data-sets at that location see if the column exist then assign random values...&lt;BR /&gt;%macro val(lib=,ds=,libname=,column=);&lt;BR /&gt; libname myfile "&amp;amp;lib";&lt;BR /&gt;&lt;BR /&gt;%if %sysfunc(exist(myfile.&amp;amp;ds))=0 %then %do;&lt;BR /&gt; %if %sysfunc(exist(myfile.&amp;amp;ds,view))=0 %then&lt;BR /&gt; %do; &lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table datasets as select distinct memname from dictionary.columns&lt;BR /&gt;where upcase(libname) = upcase("&amp;amp;lib") and upcase(name) = upcase("&amp;amp;column");&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;set datasets end=done;&lt;BR /&gt;if _n_ = 1 then call execute('data values;set ');&lt;BR /&gt;call execute("&amp;amp;lib.."!!strip(memname)!!' ');&lt;BR /&gt;if done then call execute(": keep &amp;amp;column; run;");&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=values nodupkey;&lt;BR /&gt;by &amp;amp;column;&lt;BR /&gt;run;&lt;BR /&gt; %end;&lt;BR /&gt; %end;&lt;BR /&gt; %quit:&lt;BR /&gt;%mend val;&lt;BR /&gt;%val(lib='C:\Users\Desktop\Myfiles',ds=test1,column=name);&lt;BR /&gt;&lt;BR /&gt;but gives error &lt;BR /&gt; Invalid physical name for library MYFILE.&lt;BR /&gt;ERROR: Error in the LIBNAME statement&lt;BR /&gt;.&lt;BR /&gt;File WORK.VALUES.DATA does not exist.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hate to repeat myself, but:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before putting it into a macro, do it step-by-step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;!!!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2016 11:36:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/print-constant-values-assigned-to-column-values/m-p/300736#M63561</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-26T11:36:11Z</dc:date>
    </item>
  </channel>
</rss>

