LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 1 Aug 2011 02:16:19 -0400
Reply-To:     Søren Lassen <s.lassen@POST.TELE.DK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Søren Lassen <s.lassen@POST.TELE.DK>
Subject:      Re: Getting output from one data set using vars listed in another
Comments: To: Eduardo Galvan <egalvan@ISR.UMICH.EDU>
Content-Type: text/plain; charset=ISO-8859-1

Eduardo, The simplest solution is probably to use SQL to generate an SQL statement, e.g.: /* Sample variable name list */ data vars; input varname $; cards; N001 N002 N023 ;run;

/* sample data */ data data; array N0(*) 8 N001 N002 N023; do j=1 to 200; do i=1 to dim(n0); n0(i)=ceil(ranuni(0)*5); end; output; end; keep N0:; run;

proc sql noprint; /* Create statement to create statistics table */ select catx(' ','select distinct', quote(trim(varname)),'as name,', varname,'as value,' 'count(*) as N from data group by',varname) into:stmt separated by ' union ' from vars; /* create statistics table */ create table want as &stmt; quit;

Regards, Søren

On Fri, 22 Jul 2011 16:23:52 -0400, Eduardo Galvan <egalvan@ISR.UMICH.EDU> wrote:

>The data in rangevars will simply have a variable with the field name (vname) and will have values such as these: >N001 >N002 >N023. > >I want to run frequencies on the variables (N001, N002, N023, etc.) in the second file (Section_N) so that I can have a list of all the values for each variable in the Section_N file. I am going to use this information to determine the min and max value for each variable. I'd run a proc means on each, but I need to merge other data (value labels) to the table containing the frequency output because I need to eventually exclude some values-- these vary across the different variables) when determining the min and max values for each variable. > >So I want my output to look like: > >Variable Name Value Frequency >N001 1 15 >N001 2 30 >N001 3 20 >N002 1 20 >N002 5 30 >N002 9 15 >N023 1000 10 >N023 1500 11 >N023 9993 21 > >Your help is appreciated. > >Thanks. > > > > >-----Original Message----- >From: Data _null_; [] >Sent: Friday, July 22, 2011 4:10 PM >To: Eduardo Galvan >Cc: >Subject: Re: Getting output from one data set using vars listed in another > >You don't need no stinkin' EXCEL to write SAS programs. :-) SAS has all kinds of code gen facilities but you may not need them. > >I will need example of the data you describe. I think I can picture it ok but I am too lazy to try and figure out exactly what your data looks like and the mock it up. Also show example of the output you are looking for. > >I'm not sure you will need to create individual files of each variable >summary. SAS will create a nice file with all variables. Better to >keep it all together. > > >On Fri, Jul 22, 2011 at 2:53 PM, Eduardo Galvan <> wrote: >> Hi, >> >> I have a data file (rangevars) that contains a list of certain >> variables that appear in a second data file (Section_N). I want to >> run frequencies on each variable and output the results for each to an >> individual file using the variable name as the file name before I >> merge all the individual files into a "master" file. >> >> Since I am not very advanced in my programming skills, I thought that >> I would run a proc print on the rangevars table to get the list of variables. >> At that point I would copy the output to Excel and manipulate it to >> create macro code to do what I want. However, I would like to learn >> how to have this be entirely automated. >> >> Thank you. >>

Back to: Top of message | Previous page | Main SAS-L page