BookmarkSubscribeRSS Feed
jk101564
Calcite | Level 5

Hello, I am trying to do the following task but since i am new to SAS, I need some help. If anyone can help me out. 

Generate 20 observations for the total population estimate of females that worked full-time. Also, i need to create a variable that contains the maximum earning. For example, for label $2,500 to $4,999, the variable would include value 4,999. Also, i need to 

store this data in a raw data file. Sort the data from highest amount earned to the lowest amount earned. Store this sorted data in a second raw data file. Perform another sort to order the data from highest population number to lowest population number. Store this sorted data in a third raw data file. Keep the two related data variables associated so that after each sort the amount earned is associated with the population number or the number of people that earned that amount. 

 

Here is the code i have so far.  

 

PROC IMPORT DATAFILE='file.csv' replace DBMS= csv OUT=file.population
run;

Data Fem; 
SET population; 
Where Gender = 'Female' AND Status ='Fulltime';
run;

/*Creates a raw 'txt' file to hold the data*/
DATA _NULL_
SET Fem;
FILE PRINT 'T0.txt';
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

/* Sorts the data by Salary_High in descending order (highest to lowest salary */
PROC SORT data = Fem; 
BY DESCENDING Salary_High; 
run;

/*Creates a raw 'txt' file to hold the data */
DATA _NULL_ 
SET Fem; 
FILE PRINT 'T1.txt';
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

/* Sorts the data from Highest to lowest population #'s per salary*/
PROC SORT data = Fem;
BY DESCENDING Population;
run;

/*Creates a raw 'txt' file to hold the data*/
DATA _NULL_
SET Fem;
FILE PRINT 'T2.txt'; 
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

 

 

 

2 REPLIES 2
ballardw
Super User

@jk101564 wrote:

Hello, I am trying to do the following task but since i am new to SAS, I need some help. If anyone can help me out. 

Generate 20 observations for the total population estimate of females that worked full-time. Also, i need to create a variable that contains the maximum earning. For example, for label $2,500 to $4,999, the variable would include value 4,999. Also, i need to 

store this data in a raw data file. Sort the data from highest amount earned to the lowest amount earned. Store this sorted data in a second raw data file. Perform another sort to order the data from highest population number to lowest population number. Store this sorted data in a third raw data file. Keep the two related data variables associated so that after each sort the amount earned is associated with the population number or the number of people that earned that amount. 

 

Here is the code i have so far.  

 

PROC IMPORT DATAFILE='file.csv' replace DBMS= csv OUT=file.population
run;

Data Fem; 
SET population; 
Where Gender = 'Female' AND Status ='Fulltime';
run;

/*Creates a raw 'txt' file to hold the data*/
DATA _NULL_
SET Fem;
FILE PRINT 'T0.txt';
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

/* Sorts the data by Salary_High in descending order (highest to lowest salary */
PROC SORT data = Fem; 
BY DESCENDING Salary_High; 
run;

/*Creates a raw 'txt' file to hold the data */
DATA _NULL_ 
SET Fem; 
FILE PRINT 'T1.txt';
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

/* Sorts the data from Highest to lowest population #'s per salary*/
PROC SORT data = Fem;
BY DESCENDING Population;
run;

/*Creates a raw 'txt' file to hold the data*/
DATA _NULL_
SET Fem;
FILE PRINT 'T2.txt'; 
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

 

 

 


Some example data and the actual desired result for a few records will help. It is not clear from your description whether the desired output is actually a SAS data set, a text file, multiple SAS datasets, multiple text files or specifically what any of those would look like.

Is the process one that was given to you that you must follow or what you think is an approach to a solution?

Also, this sort of sounds like homework. Is that the case?

If the objective is to only put the first value into the text files then the data set option OBS controls how many records are processed by the data step.

DATA _NULL_
SET Fem (obs=1);
FILE PRINT 'T0.txt';
PUT SEX $ POPULATION Salary_Low Salary_High;
run;

 

 

SAS has several ways of identifying the records associated with the maximum (or minimum) value of something. Here is an example using a data set that should have been included in your SAS installation.

proc means data=sashelp.class nway;
   class sex;
   id name;
   var height;
   output out=work.classsummary drop=(_type_ _freq_)
          max=maxheight maxid=maxname
   ;
run;
jk101564
Calcite | Level 5

Here is the data. Yes this is the one of the task in HW. If you can help me that would be appreciated.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 728 views
  • 0 likes
  • 2 in conversation