BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Havi
Obsidian | Level 7

Hi All

Please help me. I need a program to check the variables in a dataset and if possible list the variable type.

Example: I have 3 datasets. I need to check the variables in each dataset at the end of the month in order to track changes to the dataset structure and raise a flag if the table structure changes.

Test201207 has 2 variables:           amount, date

Test201208 has 3 variables:          amount, date and customer_id

Test201209 has 4 variables:           amount, date, customer_id and count

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I think if you make a grid with memnames down the side and variable names across and put type in the cells you can find all the answers you need with one simple report.

data

   test201207(keep=amount date)

   test201208(keep=amount cdate customer_id rename=(cdate=date))

   test201209(keep=amount date customer_id count)

   ;

   attrib amount length=8;

   attrib date length=8;

   attrib cdate length=$10;

   attrib customer_id length=$10;

   attrib count length=8;

   stop;

   call missing(of _all_);

   run;

proc contents data=work._all_ noprint

   out=contents(keep=memname name type where=(memname eq: 'TEST'));

   run;

proc print;

   run;

proc transpose out=report(drop=_name_ _label_);

   by memname;

   var type;

   id name;

   run;

proc print;

   run;

                                        customer_

Obs     MEMNAME      amount    date        id       count

1     TEST201207       1        1         .          .

2     TEST201208       1        2         2          .

3     TEST201209       1        1         2          1

View solution in original post

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

is this what you want:

proc contents data=sashelp.class out=class(keep=name type) noprint;
run;
proc print data=class;run;
                                    Obs    NAME      TYPE

                                       1     Age         1
                                       2     Height      1
                                       3     Name        2
                                       4     Sex         2
                                       5     Weight      1

Havi
Obsidian | Level 7


Thanks for your response Linlin.

Yes but I need to see how it differs from the previous datasets - what new variable has been added.

Linlin
Lapis Lazuli | Level 10

How about:

data class1 class2;
  set sashelp.class;
data class1;
  set class1;
  room=3;
data class2;
  set class2;
  grade='a';

proc contents data=class1 out=class_1(keep=name type) noprint;
proc contents data=class2 out=class_2(keep=name type) noprint;
run;
proc sort data=class_1;
  by name;
proc sort data=class_2;
  by name;
run;

data check;
  length status $ 18;
  merge class_1(in=a) class_2(in=b);
  by name;
  if a and b then status='both';
   else if a and not b then status='class_1 only';
     else status='class_2 only';

proc print;run;
                             Obs    status          NAME      TYPE

                               1     both            Age         1
                               2     both            Height      1
                               3     both            Name        2
                               4     both            Sex         2
                               5     both            Weight      1
                               6     class_2 only    grade       2
                               7     class_1 only    room        1

TomKari
Onyx | Level 15

Check out the tables in the DICTIONARY library. They make it very easy to get dataset characteristics in a machine readable form. Setting up a scheme to retain the old settings, and compare them with the new ones, should be very easy. PROC COMPARE might do the job nicely.

Tom

data_null__
Jade | Level 19

I think if you make a grid with memnames down the side and variable names across and put type in the cells you can find all the answers you need with one simple report.

data

   test201207(keep=amount date)

   test201208(keep=amount cdate customer_id rename=(cdate=date))

   test201209(keep=amount date customer_id count)

   ;

   attrib amount length=8;

   attrib date length=8;

   attrib cdate length=$10;

   attrib customer_id length=$10;

   attrib count length=8;

   stop;

   call missing(of _all_);

   run;

proc contents data=work._all_ noprint

   out=contents(keep=memname name type where=(memname eq: 'TEST'));

   run;

proc print;

   run;

proc transpose out=report(drop=_name_ _label_);

   by memname;

   var type;

   id name;

   run;

proc print;

   run;

                                        customer_

Obs     MEMNAME      amount    date        id       count

1     TEST201207       1        1         .          .

2     TEST201208       1        2         2          .

3     TEST201209       1        1         2          1

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 951 views
  • 0 likes
  • 4 in conversation