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

Hi;

I have imported a SPSS dataset into SAS. It is a big dataset, but initially I want to work on only one district,but I am unable to create a small dataset having only district level data because of format problem. The variable having names of districts is numeric in the original dataset but when I want to use IF statement, the log says Character values have been converted to numeric values. 

DATA DISTRICT;
     SET MYDATA.MICSDAT;
     IF HH7='BAHAWALPUR';
RUN;

I have also tried Proc Datasets to eliminate format and also tried to convert this variable HH7 to a charachter variable but thngs are not working.

any suggestion, where i am going wrong?

 

Thanks

 

Haroon

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your variable HH7 is numeric - with the HH7A format applied to it. 

You need to find the code that matches the formatted value and filter via that method. 

Or convert variable to character to filter. 

 

*this will display the district coding by extracting info from format. In SPSS this would have been your code table values. ;
Proc format cntlout=fmts;
Run;

Proc print data=fmts;
Where upper(fmtname)='HH7A';
Var fmtname start label;
Run;

Or use the following where clause in your original query:

Put(hh7, hh7a.) = "DISTRICT";

View solution in original post

8 REPLIES 8
Reeza
Super User

Please post a proc contents of your data as well as a proc freq of the variable, without formats. 

 

Proc contents data=mydata.micsdat;
Run;

Proc freq data=mydata.micsdat;
Table hh7;
Format hh7;
Run;
Haroon
Fluorite | Level 6

Proc Content output

Reeza
Super User

Your variable HH7 is numeric - with the HH7A format applied to it. 

You need to find the code that matches the formatted value and filter via that method. 

Or convert variable to character to filter. 

 

*this will display the district coding by extracting info from format. In SPSS this would have been your code table values. ;
Proc format cntlout=fmts;
Run;

Proc print data=fmts;
Where upper(fmtname)='HH7A';
Var fmtname start label;
Run;

Or use the following where clause in your original query:

Put(hh7, hh7a.) = "DISTRICT";
Haroon
Fluorite | Level 6

Thanks Reeza  but PUT function is not working with Where statement. syntax is correct but log says syntax error.

In the second option I have extracted the format name and labels, but what to do next to get the subset of larger data? If i should merge this fmts data with larger data and then filter by district?

Reeza
Super User

Figure out what number corresponds to your district and change your query to use that number instead of name. 

 

Or fix your where statement, the theory is correct. 

Haroon
Fluorite | Level 6

Thanks a lot Reeza your suggestion worked good for me. The obervations under HH7 are coded and I have succeded to filter them but they appear in Print in the form of District names.

Haroon
Fluorite | Level 6

output of Proc freq

Reeza
Super User
Yes, the format controls appearance. You can use the format from proc freq to remove format. Or proc datasets to remove it permanently.

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
  • 8 replies
  • 1572 views
  • 1 like
  • 2 in conversation