@melhaf wrote:
but it s print for banana
No it doesn't. At least not within that procedure. It prints it at the next proc contents.
Title remains valid until you overwrite it with another title statement or set it to blank and that's what you're seeing. Re-order your code to see that correctly.
data banana;
length banana 8 fruit 8;
do year = 2014 to 2023;
date = input(cats(put(year, 4.), '1231'), yymmdd8.);
do i = 1 to 25;
customer = cats('Customer', (year - 2014) * 25 + i);
banana = round(ranuni(0) * 100, 0.01);
fruit = ceil(ranuni(0) * 2) - 1;
output;
if i <= 10 then do;
customer = cats('Customer', (year - 2014) * 25 + i);
banana = round(ranuni(0) * 100, 0.01);
fruit = ceil(ranuni(0) * 2) - 1;
output;
end;
end;
end;
format date yymmddn8.;
drop i year;
run;
%macro check_column_types(libname=, memname=,);
proc contents data=&libname..&memname out=columns_info(keep=name type);
run;
/* Skapa temp-dataset */
data column_types;
set columns_info;
/*ATTRN (en sas-funktion som används för att hämta attribut för en variabel i ett dataset) bestämemer datatypen*/
array char_cols[*] _character_;
array num_cols[*] _numeric_;
do i = 1 to dim(char_cols);
if vname(char_cols[i]) = name then do;
column_type = 'CHAR';
output;
end;
end;
do i = 1 to dim(num_cols);
if vname(num_cols[i]) = name then do;
column_type = 'NUM';
output;
end;
end;
run;
proc print data=column_types noobs;
title 'BANANA NNANANBANANABNASBA';
run;
/* Rensa temp-datasets */
proc datasets library=work nolist;
delete columns_info column_types;
quit;
%mend;
%check_column_types(libname=work, memname=banana);
data strawberry;
length strawberry 8 fruit 8;
do year = 2014 to 2023;
date = input(cats(put(year, 4.), '1231'), yymmdd8.);
do i = 1 to 25;
customer = cats('Customer', (year - 2014) * 25 + i);
banana = round(ranuni(0) * 100, 0.01);
fruit = ceil(ranuni(0) * 2) - 1;
output;
if i <= 10 then do;
customer = cats('Customer', (year - 2014) * 25 + i);
strawberry = round(ranuni(0) * 100, 0.01);
fruit = ceil(ranuni(0) * 2) - 1;
output;
end;
end;
end;
format date yymmddn8.;
drop i year;
run;
%macro check_column_types(libname=, memname=,);
proc contents data=&libname..&memname out=columns_info(keep=name type);
run;
/* Skapa temp-dataset */
data column_types;
set columns_info;
/*ATTRN (en sas-funktion som används för att hämta attribut för en variabel i ett dataset) bestämemer datatypen*/
array char_cols[*] _character_;
array num_cols[*] _numeric_;
do i = 1 to dim(char_cols);
if vname(char_cols[i]) = name then do;
column_type = 'CHAR';
output;
end;
end;
do i = 1 to dim(num_cols);
if vname(num_cols[i]) = name then do;
column_type = 'NUM';
output;
end;
end;
run;
proc print data=column_types noobs;
title 'STRAWBERRY BERYRYEYRYRWEBERBE';
run;
/* Rensa temp-datasets */
proc datasets library=work nolist;
delete columns_info column_types;
quit;
%mend;
%check_column_types(libname=work, memname=strawberry);
... View more