The second star of Shifting Sand Land will be at the top of the pyramid, on the outside, where you have a few ways to grab it. You should have a basic understanding of the outside area of the pyramid, so make your way through the first two areas and get to the oasis. It should be noted at this time that Klepto, the vulture, will be following you around here and attempting to snag your hat. Should it manage to grab it, then you will have to grab it back via the same method as the star. If you wish to leave it alone, then Mario will take double damage without his hat.
When you get to the two pillars, keep following the path around the whirlpool of quicksand, making sure to not get sucked in by the whirlwind emanating from the whirlpool. Go up the ramp of the pyramid and over to the yellow block. There will be a higher ledge here, which will follow the outside of the pyramid, but each level will have the ledge get smaller. You might want to try and bait the Fly Guy into swooping down, so you can get it out of the way before it hits you with a flame. Once you get to the last ledge, you can actually use Mario’s crawl to slowly make your way to the star.
The much easier way of nabbing this star is by using either the Wing Cap or the Koopa shell, both of which are located on top of the stone structure near the beginning of the course. If you go with the former, fly to the base of the pyramid, square up with the entrance and do the Triple Jump, which should hopefully land you straight with the star. With the Koopa shell, you can surf over the sand and go straight to the pyramid. Ride the shell up the slanted portion of the pyramid, jumping when you stall, and you can go straight to the star.